We often customize the servlet and then rewrite the Doget and Dopost methods
public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException { Response.setcontenttype ("Text/html;charset=utf-8"); ServletInputStream in = Request.getinputstream (); String s = ioutils.tostring (in, "utf-8"); System.out.println (s);}
Parameters have HttpServletRequest and httpservletresponse they are all interfaces, so what is the implementation class?
public class Httpservletresponsewrapper extends Servletresponsewrapper implements HttpServletResponse {
The implementation class is Servletresponsewrapper, and there is a Servletresponse member in this class, but he is an interface and the implementation class is Responsefacade.
public class Servletresponsewrapper implements Servletresponse { private servletresponse response;
We often set character encodings in custom Servlets.
Response.setcontenttype ("Text/html;charset=utf-8");
He calls the Servletresponsewrapper method, which in turn invokes the method of the member.
@Override public void setContentType (String type) { this.response.setContentType (type); }
@Override public void setContentType (String type) { if (iscommitted ()) { return; } if (securityutil.ispackageprotectionenabled ()) { accesscontroller.doprivileged (new Setcontenttypeprivilegedaction (type)); } else { response.setcontenttype (type); } }
Finally know the implementation class of the response in the custom servlet ...
Implementation classes for HttpServletResponse in Tomcat