Matthew
Matthew

Reputation: 8416

How to set default character encoding in an HttpServlet, HttpServletRequest?

In the same way that

HttpServletRequest#setCharacterEncoding("UTF-8");

works to decode post data as UTF-8, I am wondering if there is a Tomcat configuration setting to have HttpServletRequest objects set to decode UTF-8 by default without having to explicitly have that line of code in my servlet.

Since we are able to set default encoding for the client side with a configuration setting (Set the default encoding to UTF-8 for all JSPs without using @page directives) it would seem to follow that there is a way to set encoding on the server side as well.

I've read in some places that setting the encoding is a job for the client side so if I am trying to go about this the wrong way, let me know.

Upvotes: 0

Views: 3653

Answers (1)

Shinichi Kai
Shinichi Kai

Reputation: 4523

You can use SetCharacterEncodingFilter. This wiki page is also helpful for you.

Upvotes: 1

Related Questions