Java Web Programming in Java Java Servlet and JSP Programming Structure and Deployment China Jiliang University
Servlet/JSP Exercise - Rules On the following pages you will find the rules and conventions for naming and deployment of your servlet and jsp files. Very important: Go directly to your directories (number "nn") and work only in these directories! Do not enter other directories! This is strictly forbidden
Servlet Exercise Compiling Servlets: package jiliang.student_nn; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.util.*; Directory Structure (example) jiliang student_nn jiliang.student_nn // Example for student_nn public class Servletstudent_nn extends HttpServlet { Servlet API: servlet-api-5.0.18.jar or servlet-api-2.4.jar javac -target 1.5 Servletstudent_nn.java Compile for Java (Tomcat) 5.5
Servlet JAR Java Servlet Archive File: A copy of the file "servlet-api-2.4.jar" can be found in the directory "servlet_jar"
Servlet Exercise Servlet Home directories URL of the Jakarta-Tomcat Server: 10.132.10.91:8180 Directory for Servlets: $TOMCAT_WEBAPPS/student-servlet/WEB-INF/classes/jiliang/student_nn URLs (Servlets): http://10.132.10.91:8180/student-servlet/servlet/servlet_name http://10.132.10.91:8180/ student-servlet/servlet/jiliang.student_nn.servletstudent_nn jiliang.student_nn.servletstudent_nn Access via FTP: Server-IP: 10.132.10.91, Port: 21 User: newhelm, Passwd: 123 Info: http://10.132.10.91:8180/student-servlet/
Servlet Exercise - Naming Summary - Your Servlet: Getting to your directory: student-servlet WEB-INF classes jiliang student_nn Naming your Servlet: nn: Important: Servletstudent_nn.java this is your number Use only this name!
Servlet Exercise - Example Source Code - Example: http://10.132.10.91:8180/student-servlet/servletstudent_00.html
JSP Exercise JSP Home directories URL of the Jakarta-Tomcat Server: 10.132.10.91:8180 Directory for JSP: $TOMCAT_WEBAPPS/student-jsp/jsp/jiliang/student_nn URLs (JSPs): http://10.132.10.91:8180/ student-jsp/jsp/jiliang/student_nn/index.jsp Access via FTP: Server-IP: 10.132.10.91, Port: 21 User: newhelm, Passwd: 123
JSP Exercise - Naming Summary - Your JSP: Getting to your directory: student-jsp jsp jiliang student_nn Naming your JSP: nn: Important: *.jsp, *.html this is your number No restrictions on names.
Servlet Exercise Compiling the servlet using the Jakarta Servlet-API: a) Download the Servlet-API file "servlet.jar". b) Install the file in the following directory: "C:\Programs\jdk_dir\jre\lib\ext\" (with jdk_dir = JDK-directory, e.g. "jdk1.3.0_02"). c) Set the classpath (e.g. using a batch file): set CLASSPATH= C:\Programs\jdk_dir\jre\lib\ext\servlet.jar d) Compile the servlet as usual: javac filename.java
Servlet Exercise User handling during an e-commerce session Write a Java Servlet that fulfils the following functions: New customer: Welcome this visitor with the message "Welcome to our shop" (or similar). Offer a form (HTML) to register this new customer asking for the necessary information. Minimum input should be: first name, last name and address; preferred product line (using the shop); allow at least four different categories. The client sends an HTTP POST request with the complete set of data from this HTML form.
Servlet Exercise Echo the accepted data back to the client in the form of an HTML table. The user (client) should receive a non-editable version of the updated information. Known (old) customer: Welcome this visitor with the message "Welcome 'first name' 'last name' " followed by basic information about former visits to the shop, like: last visit, number of visits (since), session ID, Focused advertising: Send to the known visitor customer-oriented advertisements (banner, e.g. appropriate images that are opened in a separate small window).