SWE 432 JSP and Bean Installation Instructions

11/05/2002 Update December 2003 for Java 1.4 import rules


Installing JSPs on hermes is simpler than installing servlets because no compilation is necessary. Your JSP file should go into the directory:
hermes:$CATALINA_HOME/webapps/classes/swe432/jsp/
cp X.jsp $CATALINA_HOME/webapps/classes/swe432/jsp/
You can create a symbolic link from your home directory the same way you did for servlets.

JSPs often want to interface with Java Beans or other Java classes, and you need to put the classes in the right directory. Java 1.4 has 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 beanservlet 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:
hermes:$CATALINA_HOME/webapps/classes/swe432/WEB-INF/classes

The class has to be in a package, so you need to create one. 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 $CATALINA_HOME/webapps/classes/swe432/WEB-INF/classes
mkdir gburdell
cp ~/gbean.java gburdell
javac gburdell/gbean.java

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.GBBean" %>
  2. Declare an object of type GBBean named Val:
    < jsp:useBean id="Val" scope="page" class="Gburdell.BBean" />
  3. Copy your JSP file into the JSP directory above.
  4. Now run your JSP from your browser by entering the URL:
    http://hermes.gmu.edu:8080/swe432/jsp/GBUseBean.jsp

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.

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: $CATALINA_HOME/work/Standalone/localhost/swe432/jsp/

Back to assignments page Back to schedule page