Week 2 Tasks

Servlets with Database Connectivity

  1. Start with the web application we created last week. Here's a zip file containing the entire directory structure for that web app.
    Use the following link http://localhost:8080/mywebapp/myotherform.html to verify that the web app works.
  2. We will incorporate database access in this servlet. First, create a slightly different version of Select.java by inserting the line
    package servlets;
    at the beginning of the program. ( Select.java contents ). Compile this program inside the servlets folder (the same place where WelcomeServlet.java resides).
  3. Revise WelcomeServlet.java so that it invokes Select.getNum(). Instead of
    favoriteNumber = name.length();
    arrange it so that it obtains the mobile phone number associated with the given name. Here's some code you could use:
    		String favoriteNumber;
    		try
    		{
    			favoriteNumber = Select.getNum( name );
    		}
    		catch( Exception e )
    		{
    			favoriteNumber = "no mobile number";
    		}
    	
  4. Recompile both WelcomeServlet.java and Select.java by running the command prompt on the servlets folder and issuing javac *.java.
    Make sure that the data source name is a System Data Source Name (System DSN).
    should now carry out a mobile phone number look up. This link: http://localhost:8080/mywebapp/myotherform.html

Java Server Pages

  1. Java Server Pages reduces servlet coding. Create a lookup.jsp file with the following contents .
    Create a lookupform.html that invokes lookup.jsp. ( lookupform.html contents .)
    Notice that the form is similar to myotherform.html, except that this time the form invokes the JSP instead of the servlet.
  2. Place both files inside the mywebapp folder.
    This link: http://localhost:8080/mywebapp/lookupform.html should demonstrates a working Java Server Page.

Assembling a Web App using Eclipse

  1. Unpack the eclipse package and invoke eclipse by double-clicking on the eclipse executable.
  2. Create a Dynamic Web Project. Bring together the same components you would put together in a web application: Make sure that you:
  3. Figure out how to deploy the web app.