Every servlet must implement javaxservlet Servlet interface Most servlets

Every servlet must implement javaxservlet servlet

This preview shows page 13 - 21 out of 85 pages.

° Every servlet must implement javax.servlet. Servlet interface ° Most servlets implement the interface by extending one of these classes - javax.servlet. GenericServlet - javax.servlet.http. HttpServlet Servlet APIs
Image of page 13
GenericServlet service ( ) Server Client HTTPServlet service ( ) HTTP Server Browser request response doGet( ) doPost( ) request response Generic Servlet & HTTP Servlet
Image of page 14
° The Servlet interface defines methods - to initialize a servlet - to receive and respond to client requests - to destroy a servlet and its resources - to get any startup information - to return basic information about itself, such as its author, version and copyright. ° Developers need to directly implement this interface only if their servlets cannot (or choose not to) inherit from GenericServlet or HttpServlet. Life Cycle Methods Interface javax.servlet.Servlet
Image of page 15
° void init (ServletConfig config) - Initializes the servlet. ° void service (ServletRequest req, ServletResponse res) - Carries out a single request from the client. ° void destroy () - Cleans up whatever resources are being held (e.g., memory, file handles, threads) and makes sure that any persistent state is synchronized with the servlet's current in-memory state. ° ServletConfig getServletConfig () - Returns a servlet config object, which contains any initialization parameters and startup configuration for this servlet. ° String getServletInfo () - Returns a string containing information about the servlet, such as its author, version, and copyright. GenericServlet - Methods
Image of page 16
Initialization init() Service service() doGet() doPost() doDelete() doHead() doTrace() doOptions() Destruction destroy() Concurrent Threads of Execution Servlet Life Cycle
Image of page 17
void doGet (HttpServletRequest request, HttpServletResponse response) –handles GET requests void doPost (HttpServletRequest request, HttpServletResponse response) –handles POST requests void doPut (HttpServletRequest request, HttpServletResponse response) –handles PUT requests void doDelete (HttpServletRequest request, HttpServletResponse response) – handles DELETE requests HttpServlet - Methods
Image of page 18
Provides client request information to a servlet Servlet container creates a servlet request object and passes it as an argument to the servlet's service method ServletRequest interface define methods to retrieve data sent as client request: – parameter name and values – attributes – input stream HTTPServletRequest extends the ServletRequest interface to provide request information for HTTP servlets Servlet Request Objects
Image of page 19
HttpServletRequest - Methods Enumeration getParameterNames () an Enumeration of String objects, each String containing the name of a request parameter; or an empty Enumeration if the request has no parameters java.lang.String[] getParameterValues (java.lang.String name) Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.
Image of page 20
Image of page 21

You've reached the end of your free preview.

Want to read all 85 pages?

  • Winter '14
  • Web server, JavaServer Pages, Java Servlet, Dr. Mithun Balakrishna

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

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