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
- 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
- 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:
- Place the servlet in ~/public_html/WEB-INF/classes
- Verify at http://web.njit.edu/~UCID/servlet/user_servlet (replace "UCID" with your UCID, and "user_servlet" with the name of your servlet)
- Tomcat 7 :
- Register the servlet explictly in the web.xml of user's web application
<servlet>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)
- 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
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 :
(replace "UCID" with your UCID, and "JSF_Webapplication" with the name
of your web application).
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.
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.
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.
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?").
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.
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)
- For "... starting directory", enter c
- For "... AFS username or group:", enter http
- For " Select one of above by entering its number:", enter 5