質問

I am trying to setup the right encoding for my JSP/servlet pages in Tomcat 7. Though, I have to be successful yet. I made some tries from the suggestions given by this stackexchange thread: Character encoding JSP -displayed wrong in JSP but not in URL: "á » á é » é", but they didn't work. The curious fact lies on the fact that if I let the pages "as is" the browser recognise them as having the encoding Windows-CP 1252 and when I change for UTF-8 the text is displayed correctly. But applying filters and other mechanisms the browser put the encoding as UTF-8 and is not possibile to display it correctly. In fact for the latter if I change the encoding the results are horrible at minimum.

役に立ちましたか?

解決

I got it right now. In pages JSP I am putting as first instruction:

<%@ page pageEncoding="utf-8" %>

This fixes all problems. Other possibilities like to put response.setCharacterEncoding( "UTF-8" ) as first instruction don't work.

In relation to servlets I need to setup the character encoding before to get the PrintWriter object:

response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();

These things have solved my problem of strange characters. To sum up: The problem was that the response coming out from JSP/servlet didn't have pointed that itself was encoded in UTF-8

他のヒント

Maybe is not a JSP problem. Have you tried doing that in the page, directly?

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
...
</head>

Also, try to save the page in UTF-8 format

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top