Department Logo Information Services and Technology

Tomcat


General Information about Servlets and Java Server Pages
When and why do I have to wait for Tomcat to restart before I can access my JSP or Servlet?
Why doesn't the installed Tomcat recognize my servlets?
Can I set up my own Tomcat server on university systems for short term class assignments?
Why can't users without root authority access ports below 1024?
How to deal with a WAR file
Sample code

General Information about Servlets and Java Server Pages

  • Servlets and Java Server Pages can be served on web.njit.edu from a user's public_html directory.
  • First make sure that your login directory is correctly set up for Web pages. See: Home Page Setup .
  • Once your login directory is correctly set up, your login directory and public_html directory can be set up for Tomcat.
  • /usr/ucs/bin/tomcat.setup configures your login directory and public_html directory to enable web.njit.edu to serve servlets and Java server pages.
  • Explicit instructions regarding the Tomcat server are given when tomcat.setup is run.
  • To run tomcat.setup, log in to your account on any AFS Unix client (e.g., afs1.njit.edu to afs34.njit.edu, osl1.njit.edu-osl29.njit.edu), and enter:

    tomcat.setup


JSP test page
Sample code - index.jsp
How do deal with a WAR file
Note: The tomcat server restarts daily at approximately 6:00 AM, 2:00 PM and 8:00 PM. Your servlets will not become available until after the server completes the restart, which takes about 20 minutes. Additionally, certain changes to your WEB-INF directory will not become available until after the Tomcat server restarts.

UCS WILL NOT RESTART THE TOMCAT SERVER BY REQUEST


Return to top.


When and why do I have to wait for Tomcat to restart before I can access my JSP or Servlet?

Only the first time you set up Tomcat and establish a directory for your code. After that, once Tomcat knows where to look for your code, new code can be added and old code changed and Tomcat will pick it up.

Return to top.


Why doesn't the installed Tomcat recognize my servlets?

Note that the installed version of Tomcat uses the servlet invoker. Tomcat will only handle servlets if the URL is in the form : http://web.njit.edu/~/servlet/ If you edit the default web.xml, you MUST maintain the servlet invoker. This is non-standard, but was necessary to avoid configuring Tomcat specifically for each student project.

Return to top.


Can I set up my own Tomcat server on university systems for short term class assignments?

Yes, you can, and this may be preferable to using the already installed versions for courses where you are learning to configure Tomcat yourself. To avoid interfering with other users, please use only the systems running Linux osl1 to osl29 or the systems running Solaris from afs1 through afs35 and use a port from the "Dynamic" range (see "Why can't users without root authority access ports below 1024?").

Return to top.


Why can't users without root authority access ports below 1024?

The Internet Assigned Numbers Authority (www.iana.org) governs port assignment. see http://www.iana.org/assignments/port-numbers for more information. The important notes from this document are : "The Well Known Ports are those from 0 through 1023." "The Well Known Ports are assigned by the IANA and on most systems can only be used by system (or root) processes or by programs executed by privileged users." "The Dynamic and/or Private Ports are those from 49152 through 65535" Students should use arbitrary ports from the "Dynamic" range for projects. This will minimize interference with other processes.

Return to top.


How to deal with a WAR file

Recommended Method

Manually expand the *.war file in the WEB-INF directory in your <public_html> directory.

Alternate Method - may introduce a security risk

This method gives the Tomcat server write permission in your WEB-INF directory and subdirectories.

  • Log into one of the Solaris AFS clients (afs1.njit.edu - afs35.njit.edu) or Linux AFS clients (osl1.njit.edu - osl29.njit.edu)

    cd ~/public_html/WEB-INF

  • Run:

    /usr/ucs/bin/set.afs.perms.recur

  • For "... starting directory", enter c
  • For "... AFS username or group:", enter http
  • For " Select one of above by entering its number:", enter 5

Return to top.


Sample code

  <html>
  <head>
  <title>Hello from JSP</title>
  <%!
  String message = "Hello, World. From JSP test page Tomcat is running.";
  %>
  </head>
  <body>
  <hr color="#000000" />
  <center>
  <h2><font color="#3366cc"><%= message%></font></h2>
  <h3><font color="#0000ff"><%= new java.util.Date() %> </font></h3>
  <hr color="#000000" />
  </center>
  </body>
  </html>

Return to top.