g Firefox Safari etc boxshadowdwn Web server eg Apache Netscape Enterprise IIS

G firefox safari etc boxshadowdwn web server eg

This preview shows page 4 - 8 out of 30 pages.

Clients: Web browsers, e.g. Firefox, Safari, etc. boxshadowdwn Web server: e.g. Apache, Netscape Enterprise, IIS boxshadowdwn CGI and HTTP protocols: request method, headers etc, as for CGI boxshadowdwn Servlet container (e.g. Tomcat): running JVM, coupled to the Web server, loads and maintains servlets, session info, object store boxshadowdwn Servlet: A Java class that implements a particular Web application
Image of page 4
50 Servlets 28 Oct 2010 CSCC09 Programming on the Web 5 50 Servlets CSCC09 Programming on the Web 9 ServletContext Servlet class doGet( HttpServletRequest, HttpServletResponse) doPost ... HTTP request Servlet Container/Engine (e.g. tomcat) Web server Instantiate new Servlet thread Servlet output Servlet input HTTP response Servlet Operation 50 Servlets CSCC09 Programming on the Web 10 Request Life Cycle boxshadowdwn client makes a request by specifying a URL+additional info. Basically a method call, naming the method and its arguments. boxshadowdwn Web server (WS) specified in the URL receives the request. boxshadowdwn WS identifies the request as a servlet request. boxshadowdwn WS passes the request to the servlet container such as Tomcat (usually tightly coupled to WS). boxshadowdwn Servlet container locates the specified servlet (Java code, loaded and running in the container JVM). ServletContext Servlet class doGet HttpServletRequest HttpServletResponse doPost ... HTTP request Servlet Container/Engine (e.g. tomcat) Web server Instantiate new Servlet thread Servlet output Servlet input HTTP response
Image of page 5
50 Servlets 28 Oct 2010 CSCC09 Programming on the Web 6 50 Servlets CSCC09 Programming on the Web 11 Request Life Cycle boxshadowdwn Servlet container feeds the request parameters to the servlet through HttpServletRequest. boxshadowdwn Servlet executes in a separate thread. boxshadowdwn Servlet can store/retrieve objects (possibly session-scoped) from the Servlet context. boxshadowdwn output of the servlet is sent via a PrintWriter back to the requesting Web browser via the Servlet container through HttpServletResponse. boxshadowdwn Servlet continues to be available to service requests in the servlet container. ServletContext Servlet class doGet HttpServletRequest HttpServletResponse doPost ... HTTP request Servlet Container/Engine (e.g. tomcat) Web server Instantiate new Servlet thread Servlet output Servlet input HTTP response 50 Servlets CSCC09 Programming on the Web 12 Writing a Servlet 1. Subclass HttpServlet 2. Override doGet( .... ) method 3. Use HttpServletRequest object to access parameters, etc. circleshadowdwn getParameter("paramName") 4. Use HttpServletResponse object to create HTTP response message circleshadowdwn set Content Type circleshadowdwn get PrintWriter circleshadowdwn send HTML to client via PrintWriter 5. Don't use instance variables (generally a single Servlet object instance is shared among all threads); instead use local variables within methods or a synchronized class variable.
Image of page 6
50 Servlets 28 Oct 2010 CSCC09 Programming on the Web 7 50 Servlets CSCC09 Programming on the Web 13 Basic Servlet Template import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class SomeServlet extends HttpServlet {
Image of page 7
Image of page 8

You've reached the end of your free preview.

Want to read all 30 pages?

  • Spring '10
  • Alan
  • World Wide Web, Web server, HTTP cookie, Java Servlet, Servlets CSCC09 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