Java Servlets - PowerPoint PPT Presentation

About This Presentation
Title:

Java Servlets

Description:

Java Servlets CS-422 Application Mapping Your servlet application will be mapped to a directory structure: myapp maps to some directory C:/docs/apps/myapp in ... – PowerPoint PPT presentation

Number of Views:126
Avg rating:3.0/5.0
Slides: 14
Provided by: Pari173
Category:

less

Transcript and Presenter's Notes

Title: Java Servlets


1
Java Servlets
  • CS-422

2
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
  • cdocs/apps/myapp/Web-inf/classes

3
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.

4
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

5
Servlet Life (more)
  • Once the servlets life cycle us up (when all
    associated threads quiesce) the destroy( ) method
    will automatically be run

6
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

7
Scope
8
J2EE Application Servers
  • Tomcat Apache Foundation Open Source
  • JRUN Macromedia
  • WebSphere IBM
  • BEA Weblogic BEA
  • Sun Java System Application Server SUN
  • Oracle Application Server Oracle Corp.

9
Deployment
  • Tomcat v.4 (Apache Foundation, Jakarta Project)
  • Implements the Servlet 2.3 and JSP 1.2
    Specifications
  • Servlet 2.3 Specification
  • Outlines requirements for deploying servlets
  • Directory Structure
  • Deployment Descriptors

10
Directory Structure
  • /application
  • /application/WEB-INF
  • Web.xml (deployment Descriptor)
  • /application/WEB-INF/classes
  • Compiled class files
  • May be a WAR (Web Archive file containing all
    class files) create using the JAR application
    found in the JSDK bin directory

11
Deployment Descriptors
  • XML file describing the application
  • Used by the server to deploy the application
  • DTD is at java.sun.con/j2ee/dtds/web-app_2_2.dtd

12
Web.xml (sample)
ltweb-appgt ltdisplay-namegtCS422Samplelt/display-nam
egt ltdescriptiongtStefliks Sample App for
CS422lt/descriptiongt ltservletgt
ltservlet-namegtBrowserDataServletlt/servlet-namegt
ltservlet-classgtBrowserDataServletlt/servlet-cla
ssgt lt/servletgt ltservlet-mappinggt
ltservlet-namegtBrowserDataServletlt/servlet-namegt
lturl-patterngt/steflik/BrowserDataServletlt/url-
patterngt ltservlet-mappinggt lt/web-appgt
13
Web Application Archive files
  • jar cvf mywebapp.war
Write a Comment
User Comments (0)
About PowerShow.com