![]()
![]() |
JavaServer Pages and Java Servlets
This document describes the requirements for deploying Java servlets and JSP-enabled web pages on the Department of Computing web-server java.doc.gold.ac.uk. It does not describe the JavaServer Pages or Java Servlet specifications (see the links at the bottom of this page for those) and is not a tutorial on how to create servlets or JSP-enabled web pages. Assuming you have created your servlets or JSP pages, this document explains where they should be placed and how they can be accessed via the web. The JSP/Servlet EngineThe JSP/servlet engine (Apache Tomcat) is running on host java.doc.gold.ac.uk. It can serve .html and .jsp pages from the public_html subdirectory in your home directory. It can also run Java servlets defined in a subdirectory of public_html called WEB-INF. You may already have one or both of these directories if you have created other types of web pages on the server (.html, .php, etc). If not, just create them and make sure their permissions allow public access. To access your public_html directory via tomcat, you append your username to the hostname, like this: http://java.doc.gold.ac.uk/ma123ab Note that you do not need to put a '~' before your username. JavaServer PagesThe filenames of your JSP pages should be given the extension .jsp. For example, if user ma012zx had a JSP page called Hello.jsp in their public_html directory, it would be activated by the URL: http://java.doc.gold.ac.uk/ma012zx/Hello.jsp Java ServletsThe servlet engine expects to find the .class files for your Java servlets (or JavaBeans) in the directory: public_html/WEB-INF/classes You will need to create this directory if it doesn't already exist. Your .class files should then be copied into the classes directory. You can include extra or third-party packages (or any other .jar file) in your applications by placing them into the lib directory: public_html/WEB-INF/lib To configure your servlet for web access, you need to tell tomcat how to run it. This is done by creating a file in your WEB-INF directory called web.xml (or updating it if it's already there). The file needs to specify at least two things about your servlet; the servlet class name and the URL pattern to match. See this example web.xml file for details of how to do that. To access a servlet via the web, you just add the URL pattern you specified for the servlet in the web.xml file after your username in the tomcat URL. For example, a servlet called 'Hello.class' in the 'public_html/WEB-INF/classes' directory of user ma012zx that is defined with a URL pattern of /Hello in web.xml would be referenced using the URL: http://java.doc.gold.ac.uk/ma012zx/Hello Servlet Tips
Further Information
|