Deep Anatomy tomcat-Chapter II: A Simple servlet container (2)

Source: Internet
Author: User

Content: There are some security issues in the previous article because we need to transform request and response into ServletRequest and Servletresponse, A servlet programmer who understands how this servlet container works can transform ServletRequest and servletresponse down and then invoke the parse () of request and response. and Sendstaticresource (). So we need to use the appearance class to solve, add two Requestfacade and Responsefacade, then each have request and response, and then each call the corresponding method. So just change the code accordingly. Only the difference code is given here.

HttpServer2:

if (Request.geturi (). StartsWith ("/servlet/")) {          ServletProcessor2 processor = new ServletProcessor2 ();          Processor.process (request, response);        }

ServletProcessor2

Servlet servlet = null;    Requestfacade Requestfacade = new Requestfacade (request);    Responsefacade Responsefacade = new Responsefacade (response);    try {      servlet = (servlet) myclass.newinstance ();      Servlet.service ((ServletRequest) Requestfacade, (servletresponse) responsefacade);    }    catch (Exception e) {      System.out.println (e.tostring ());    }    catch (Throwable e) {      System.out.println (e.tostring ());    }


Deep Anatomy tomcat-Chapter II: A Simple servlet container (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.