4/10/03 CSE 403 CSE 403: Servlet Technology Zach Crisman ( zcrisman@cs ) Shane Cantrel (shanec@cs) 4/10/03
4/10/03 CSE 403
CSE 403: Servlet Technology
Zach Crisman (zcrisman@cs)
Shane Cantrel (shanec@cs)
4/10/03
4/10/03 CSE 403
CGI (Common GatewayInterface) vs Servlets
n Separate Processfor each connection
n No StandardLibraries/Languages
n State not savedbetweenconnections
n One Serlvet EngineProcess
n JavaLibraries/Language
n State saved untilservlet destroyed
4/10/03 CSE 403
Tomcat & How We Will BeUsing it
n Official Reference Implementation of JavaServlet Technology
n A Servlet Engine & Normal Webservern Everyone will be running an different instance
of Tomcat on a different port numbers(‘81’+instance number)
n Will install war (Web Application Resource)files via Tomcat management tasks in Ant
4/10/03 CSE 403
Where do I find this stuff?/*For generic , protocol independent servletfunctionality*/
import javax.servlet.*;
/*For servlets that will use the http protocol(WWW Based)*/
import javax.servlet.http.*;
Tutorial @http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets.html
API @http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/package-summary.html
Tomcat: Kick Start by Bond & LawFocus on Chapters 1,3,4,6 for this assignment (Don’t worry about JPS stuff)
4/10/03 CSE 403
GenericServlet
n ProtocolIndependent
n Overrideservice()whenextended
n Must write one’sown means ofhandling requests
Image from Java ServletProgramming by Jason Hunter
4/10/03 CSE 403
HttpServletn ExtendsGenericServlet()
n Overide doGet(…) &doPost(…)
n Already understandshttp
n Majority of servletsextend Image from Java Servlet
Programming by Jason Hunter
4/10/03 CSE 403
HttpServlet Skeletonimport javax.servlet.*;
import javax.servlet.http.*;
public class ServletSkeleton extends HttpServlet {public void doGet(HttpServletRequest req,
HttpServletResponse res)throws ServletException, IOException {}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {}}
4/10/03 CSE 403
GET vs POST
GET
- retrievinginformation
- html/images
- parameters listed inURL
POST
- send information
- uploads/forms
- parameters hiddenwithin header
4/10/03 CSE 403
Servlet Lifecyclen Timing of Lifecycle not specified
by serlvet specn Servlet may be destroyed/
instantiated when you leastexpect itinit() only called once in lifecycle
n Multi-threaded environmentn destory() should not only free
resources but also save statethat will be required in anotherinstance
n A servlet is only a instance of aclass that is dynamically loadedinto the servlet engine (Tomcat)
4/10/03 CSE 403
Database Info
n PostgreSQL 7.3 installed on rockhopper &adeliehttp://www.postgresql.org/docs/
n JDBC interface will be installedn Tomcat: Kick Start, ch 9 (general using
databases w/ Tomcat)n Everyone will have accounts already setup on
the DB systemn w/ database concurrency is not a problem
when storing data
4/10/03 CSE 403
Web Setup
n MIME Settingsn .jad
n text/vnd.sun.j2me.app-descriptor
n .jarn application/java-archive
n The settings are preset on Tomcat, butnot on other servers.
n http://hydrus.net/midlets
4/10/03 CSE 403
Downloading the Midlet
4/10/03 CSE 403
Running the Midlet
Noticeunpredictable
errors