China Jiliang University

Web Programming in Java

Java Servlet and JSP Programming

Structure and Deployment China Jiliang University

Java Web Applications,  Helmut Dispert 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

Java Web Applications,  Helmut Dispert China Jiliang University Servlet Exercise

Compiling Servlets: Directory Structure (example) package jiliang.student_nn; jiliang import java.io.*; import javax.servlet.*; student_nn import javax.servlet.http.*; import java.net.*; jiliang.student_nn import java.util.*; // Example for student_nn public class Servletstudent_nn extends HttpServlet {

Servlet API: servlet--5.0.18.jar or servlet-api-2.4.jar javac -target 1.5 Servletstudent_nn.java

Compile for Java (Tomcat) 5.5

Java Web Applications,  Helmut Dispert China Jiliang University Servlet JAR

Java Servlet Archive File:

A copy of the file "servlet-api-2.4.jar"

can be found in the directory "servlet_jar"

Java Web Applications,  Helmut Dispert China Jiliang University Servlet Exercise

Servlet Home directories

URL of the Jakarta-Tomcat : 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/ Java Web Applications,  Helmut Dispert China Jiliang University Servlet Exercise - Naming

Summary - Your Servlet:

Getting to your directory: ĺ student-servlet ĺ WEB-INF ĺ classes ĺ jiliang ĺ student_nn

Naming your Servlet: Servletstudent_nn.java

nn: this is your number

Important: Use only this name!

Java Web Applications,  Helmut Dispert China Jiliang University Servlet Exercise - Example

Source Code - Example:

http://10.132.10.91:8180/student-servlet/Servletstudent_00.

Java Web Applications,  Helmut Dispert China Jiliang University 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 (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

Java Web Applications,  Helmut Dispert China Jiliang University JSP Exercise - Naming

Summary - Your JSP:

Getting to your directory: ĺ student-jsp ĺ jsp ĺ jiliang ĺ student_nn

Naming your JSP: *.jsp, *.html

nn: this is your number

Important: No restrictions on names.

Java Web Applications,  Helmut Dispert China Jiliang University 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

Java Web Applications,  Helmut Dispert China Jiliang University 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.

Java Web Applications,  Helmut Dispert China Jiliang University 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).

Java Web Applications,  Helmut Dispert