Implementation classes for HttpServletResponse in Tomcat

Source: Internet
Author: User

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

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.