Reputation: 679
In a servlet java class,I type request.setCharacterEncoding("utf-8"), and then I want to see what this method actually is in the source code,and I use CTRL+LEFT-CLICK to enter the method's source code
And then it goes to the ServletRequest Interface, in the Interface the method's code is
public void setCharacterEncoding(String env)
throws java.io.UnsupportedEncodingException;
It's surely an empty method because ServletRequest
is an Interface.
Where can I see what this method actually have done to set the encoding?
Upvotes: 0
Views: 325
Reputation: 1370
This method is implemented by servlet container. For example for Tomcat 8.5 implementation reside in org.apache.catalina.connector.Request#setCharacterEncoding and looks like:
public void setCharacterEncoding(String enc) throws UnsupportedEncodingException {
if(!this.usingReader) {
B2CConverter.getCharset(enc);
this.coyoteRequest.setCharacterEncoding(enc);
}
}
As you can see it is just validates encoding name and set internal request implementation field in which encoding stored. You can search you servlet container source code for implements HttpServletRequest
and look at implementation.
Upvotes: 2