JSP: how to read unicode from forms

Are you having encoding problems while trying to read multilingual data from a JSP form? That is because JSP by default is trying to interpret your input as ISO-8859-1. That’s fine unless you have a form that sendsUTF-8.

The problem can be eliminated by simply adding the following line of before you do any calls to getParameter():

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
...
request.setCharacterEncoding("utf-8");
...
}

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>