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?

 

 

General Information about Servlets and Java Server Pages

  • Servlets, Java Server Pages and Java Server Faces can be served from web.njit.edu from a user's public directory, via an Apache Tomcat Server.
    • 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 public_html directory to enable web.njit.edu to serve Servlets, Java Server Pages and Java Server Faces.
  • Currently, both Tomcat 5 and Tomcat 7 are offered. Users can choose the either of them or both of them.
  • 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., afsN.njit.edu, N=1,2,...,34; oslN.njit.edu, N=1,2,...,30 and 51,52,...,84), and
    enter: tomcat.setup
  • After you have run tomcat.setup and after the server has restarted (see schedule below), you can verify Tomcat is working properly for your UCID by checking the HelloWorld servlet installed by tomcat.setup.
  • Tomcat 7 and Tomcat 5 use different mechanisms of servlets.
    • Tomcat 5:
    • Tomcat 7 :
      • Register the servlet explictly in the web.xml of user's web application
        Example:

        <servlet>
          <servlet-name>HelloWorld</servlet-name>
          <servlet-class>HelloWorld</servlet-class>
        </servlet>
        <servlet-mapping>
          <servlet-name>HelloWorld</servlet-name>
          <url-pattern>/webapps7/HelloWorld</url-pattern>
        </servlet-mapping>

        Note:  the url-pattern parameter must start with "/webapps7"
      •  
      • Verify at : http://web.njit.edu/~UCID/webapps7/user_servlet (replace "UCID" with your UCID, and user_servlet with the url pattern of servlet in web.xml)
        Example:

      http://web.njit.edu/~abc12/webapps7/HelloWorld

  • Java Server Faces 2.0
    • Java Server Faces 2.0 works under Tomcat7.0, but not under Tomcat 5.
    • All configuration files - such as web.xml and faces-config.xml -
      must be in ~/public_html/tomcat7/WEB-INF (tomcat.setup provides a default web.xml, which users can modify)
    • All JSF2.0 jar files must be in ~/public_html/tomcat7/WEB-INF/lib (tomcat.setup provides JSF 2.1.14 as the default version)
    • If the above HelloWorld works, but your own Java servlets do not, please contact your instructor for assistance.
    • All JSF2.0 java class files must be in ~/public_html/tomcat7/WEB-INF/classes
    • All JSF2.0 application web pages must be in ~/public_html/tomcat7/webapps7

    Directory Structure


    The structure of the $HOME/public_html/tomcat7 directory (.) :
    .
    |____WEB-INF --> All web application configuration files, including web.xml
    |  |____classes --> All servlet files (java class files) of your web application
    |  |____lib --> All jar files of your web application
    |____webapps7 --> Your web application


     
  • After the Tomcat server has restarted, verify at :
    http://web.njit.edu/~UCID/webapps7/JSF_Webapplication
    (replace "UCID" with your UCID, and "JSF_Webapplication" with the name
    of your web application).

  •  Example:

    http://web.njit.edu/~abc12/webapps7/.....

  • If the above HelloWorld works, but your own Java servlets do not, please contact your instructor for assistance.


JSP test page Click to check that the Tomcat 7 server is running for JSP.
xhtml test page Click to check that the Tomcat 7 server is running for xhtml.
JSP test page Click to check that the Tomcat 5 server is running for JSP.
Servlet test page Click to check that the Tomcat 5 server is running for servlets.
How do deal with a WAR file
Note: The tomcat server restarts at every hour on the hour, in order to recognize any changes in users' public_html directories. Servlets will not become available until after the server completes the restart, which takes about 3 minutes. Additionally, certain changes to your WEB-INF directory will not become available until after the Tomcat server restarts.

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.

Last Updated: August 24, 2017