Your Web application is stored in a directory and deployed as a war file Top

Your web application is stored in a directory and

This preview shows page 8 - 11 out of 16 pages.

Your Web application is stored in a directory (and deployed as a war file) Top level directory of the Web application is the document root of the application, containing JSP pages and static Web resources (or subdirectories of JSP, etc.) Document root contains a sub-directory called WEB-INF, containing web.xml – the deployment descriptor classes – a directory containing server classes (e.g., servlets) lib di t th t t i JAR hi f lib i Take a look at your Web App in your NetBeans or © Robert Kelly, 2001-2010 15 lib – a directory that contains JAR archives of libraries Package directories can be either in the document root or the WEB-INF/classes directory Eclipse project pane How to Specify the Servlet in Your HTML A URL is used to request that the container run your servlet (in an anchor tag or form tag) URL contains the host name, port (optional), and path In a servlet container, the path can be mapped (what you see is not always what you get) © Robert Kelly, 2001-2010 16 There is no helloworld file
Image of page 8
Session 5 – Servlet Intro Internet Commerce Programming 9/19/2010 9 © Robert Kelly, 2001-2010 How URLs Run Servlets Context name The servlet container evaluates the URL request to see if the first part of the path matches a context name If the path matches a context name, the context name is mapped to a Web application root © Robert Kelly, 2001-2010 17 directory (using the web.xml deployment descriptor) Deployment Descriptor (web.xml) Used to deploy your Web application (i.e., servlets, JSPs, etc.) N tB di l f D l t D i t (b l ) NetBeans display of Deployment Descriptor (below) © Robert Kelly, 2001-2010 18 You can use different names to identify the servlet in different places
Image of page 9
Session 5 – Servlet Intro Internet Commerce Programming 9/19/2010 10 © Robert Kelly, 2001-2010 Web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation=" 2 4.xsd"> _ _ <servlet> <description>A "first" servlet that simply outputs Hello WWW in the browser</description> <servlet-name>HelloWorld</servlet-name> <servlet-class>lectures.HelloWorld</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloWorld</servlet-name> <url-pattern>/helloworld.html</url-pattern> </servlet-mapping> <session-config> © Robert Kelly, 2001-2010 19 <session-timeout>30</session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> Servlet Life Cycle Initialization – by the Web server or the first invocation of the servlet init method is executed when servlet is started Servlet object remains alive to handle requests service method – called by the Web Server Checks the http method and calls doGet, doPost, etc.
Image of page 10
Image of page 11

You've reached the end of your free preview.

Want to read all 16 pages?

  • Fall '08
  • Kelly,R
  • World Wide Web, Web server, HTTP cookie, Java Servlet, Robert Kelly, Internet Commerce Programming

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes