SWE 432 JSP and Bean Deployment Instructions

Update December 2003 for Java 1.4 import rules
Update March 2009 for new apps cluster
Update October 2009 change to JSP location
Update November 2011 change to new server configuration

Deploying JSPs on our apps cluster is simpler than deploying servlets because we do not need to compile. Your JSP file should go into the directory on apps-swe432:
  • cp X.jsp /data/apps-swe432/swe432/jsp/
You can create a symbolic link from your home directory the same way you did for servlets.
  • cd
  • ln -s /data/apps-swe432/swe432/jsp/ jsp

You can create a package for your JSPs the same way you did for servlets. Create the package directory in /data/apps-swe432/swe432/jsp/:
  • mkdir /data/apps-swe432/swe432/jsp/offutt
To deploy your JSP in the package, you do not need to add a package command. Tomcat will add that for you when it converts the JSP to a Java servlet. A simple example is in my package:
  • http://apps-swe432.vse.gmu.edu:8080/swe432/jsp/offutt/date.jsp
  • Source for date.jsp: date.jsp (Note: Firefox shows the source for this file, but IE tries to interpret it as HTML.)
  • Java servlet class for date.jsp: date_jsp.java (Created Oct 2009)

JSPs often need to interface with Java Beans or other Java classes, and you need to put the classes in the right directory. Java 1.4 imposed the additional requirement that the Java import command can only be used if the classes are in a package. The key to the linking is that the JSP is converted to a Java servlet, which is then compiled by the servlet engine. Therefore the bean's package directory has to be in a directory that is in the Java CLASSPATH of the servlet engine, or else it will not be found when the JSP is compiled. Conveniently, you can put Java classes in the same directory with your servlets:

The class has to be in a package, so you need to create one. (You have probably already done this for your servlets, if so, just skip this step.) Each Java package has its own subdirectory, so create a subdirectory with your user name under the classes/ directory. Assume your username is gburdell, your bean class is named gbean.java, and it is in your home directory. Modify gbean.java to add the statement: package gburdell; in the first line. Then create the package:
  • cd /data/apps-swe432/swe432/WEB-INF/classes
  • mkdir gburdell
  • cp ~/gbean.class gburdell

Please note that you can access any Java class from a JSP.

With that set up, you need to do the following to use a Java bean from a JSP. Again, assume your bean is called "gbean", and the JSP is called "gbuseBean.jsp":

  1. Import the bean into gbuseBean.jsp:
    <%@ page import="gburdell.gbean" %>
  2. Declare an object of type gbean named Val:
    <jsp:useBean id="Val" class="gburdell.gbean" scope="page" />
  3. Copy your JSP file into the JSP directory above.
  4. Now run your JSP from your browser by entering the URL:

Remember that the first time you access the URL, the servlet engine will translate your JSP file into a Java servlet class, compile the class, then run it as a servlet. You will see a noticeable delay. The servlet engine also translates and compiles if you change the JSP file (if the timestamp of the .jsp is newer than the timestamp of the .class file).

Also, if you want a servlet to call a JSP, use the address: /jsp/jsp_file.jsp.

The servlet's .java files are put into: /usr/share/tomcat6/work/Catalina/apps-swe432.vsnet.gmu.edu/swe432/org/apache/jsp/jsp/