Professional Documents
Culture Documents
CS-422
Application Mapping
• Your servlet application will be mapped to a directory structure:
– “myapp” maps to some directory C:/docs/apps/myapp
– in the myapp directory create a directory called “Web-inf”
• in Web-inf create
– classes
– jsp
– lib - use this for common things like JDBC drivers
– sessions
• these directories are used for the various components of your application
– when invoking your servlet
• http://www.myserver.com/myapp/servlet/servletname
• the “magic name” myapp/setvlet will really refer to
– c:docs/apps/myapp/Web-inf/classes
Deploying your application
• To deploy a servlet based application create a .war (web archive) file
containing all of the files needed for the application and place it on the
server
• the servlet container will work from the web archive extracting files
as needed
– the base JVM has all of the classes it needed for working with files in the
various versions of zipped files.
• Use the JDK JAR utility to create your .war file
– ex cd myapp; jar -cvf myapp.war (make sure that …JDKnnn/bin is in
your path and all of the files in the current directory will be placed into
the file myapp.war
– copy the .war file to the webapp directory of your server and its work
– make sure to back-up both your development directory and your deployed
war file.
Servlet Life
• A servlet can come into existence for two reasons:
– it was configured to be loaded on start-up of the servlet engine
– a user request called for it
• a servlet object is created on the main thread
• init( ) is started on a secondary thread
– the servlets init( ) method is guaranteed to be called once (and only once)
for the life of a given servlet.
– init( ) is guaranteed to complete before any service methods are invoked.
• the main thread for the servlet will terminate at the end of the init( )
• when a request for the servlet is received the servlet engine spawns a
new thread and calls the appropriate service( ) method
– in the case of http this will be:
• doGet
• doPost
• doDelete
• doOptions
• doPut
• doTrace
Servlet Life (more)
• Once the servlets life cycle us up (when all associated threads quiesce)
the destroy( ) method will automatically be run
Servlet APIs
• The servlet APIs are split into two packages:
– javax.servlet
• contains classes and interfaces that implement generic, protocol independent
servlets, having this generiv layer allows it to be extended other protocols (like
IIOP)
– javax.servlet.http
• extends javax.servlet for the HTTP protocol
– javax implies it is an official java extension
• TOMCAT is the official reference implementation
Scope