Instructions for running servlets etc on the Unix Remote Desktop


Table of contents

 


Overview

 

 


Getting your first webpage served

 

 


Getting your first servlet to run

 

  • Step 1: Modify the given example. The directory /SimpleWebServerJar/servlets/ should already have a servlet called HelloWorld in it. Modify this to print out something beyond "Hello World".

  • Step 2: Compile.
    Note that servlet library classes are NOT in the standard distribution of Java. These are separately distributed in a file called servlet.jar. Hence, you need to have servlet.jar in your classpath.

  • Step 3: Run the webserver:
      cd
      cd cs2113
      cd SimpleWebServerJar
      java Serve
      
  • Step 4: Access the servlet. For example, if your assigned port is 40013, use this URL in your browser (any browser from any machine with GW access).
      http://unix.seas.gwu.edu:40013/servlets/HelloWorld
      
  • Step 5: Examine the servlet.properties file. The directory /SimpleWebServerJar/ should have a file called servlet.properties that tells the webserver where to find the code (.class file) for a servlet.

    Important: Each time you create a new servlet, you must enter the servlet in this file and re-start the webserver.

 


Parameters

 
This section shows you how to run the TestForm servlet that prints out form parameters:

  • Step 1: Locate the file TestForm.java in the servlets/examples directory. Does the code have port numbers buried in it? If so, you'll have to change the port number to your assigned port number.

  • Step 2: Compile the servlet.

  • Step 3: Make sure the servlet.properties file contains the correct path to this servlet. The path should be:
    servlet.TestForm.code=/servlets/examples/TestForm
    

  • Step 4: Locate the HTML file testform.html in the webroot/examples directory. This is the file to access.

  • Step 5: Important: Edit testform.html to change the form URL in testform.html so that it uses your assigned port number.

  • Step 6: Run the webserver. Check that the servlet got loaded by the webserver and that the webserver is listening at your assigned port.

  • Step 7: Access the file testform.html from a browser
      http://unix.seas.gwu.edu:40013/examples/testform.html
      

  • Step 8: Modify the HTML to contain a hidden parameter and run the servlet again to make sure that hidden parameters are printed out.

  • Important: You will eventually need to edit all the HTML files in the webroot/examples directory. to use your assigned port number.
 


Session tracking

 
This section shows you how to run the PageCount servlet that prints out form parameters:

  • Step 1: Modify the servlet source to use your assigned port number. This is in the line that writes out the "form" action command in HTML. Then compile the servlet.

  • Step 2: Modify the webroot/examples/pagecount.html file to use your port number.

  • Step 3: Run the webserver and access pagecount.html.



© 1998, Rahul Simha (revised 2017)