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)