Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Japanese characters are broken

843842Nov 26 2003 — edited Feb 12 2005
The code below prints the Japanese text properly in both System console and in browser
<%@ page contentType="text/html; charset=Shift_JIS" %>
<html>
<body>
<form>
<%
request.setCharacterEncoding("Shift_JIS");
String value = request.getParameter("txtJapan");
System.out.println("Value : " + value);
out.println("Value : " + value);
%>
<input name="txtJapan" >
<input type="SUBMIT" />
</form>
</body>
</html>
However the same code is not working (i.e. Japanese characters are not correctly displayed) when this Page is called thru faces servlet. I have also tried using JSF components on this page, but they too don't display as expected.

Even after setting the content type and charcter encoding to Shift_JIS in JSP page (using the page directive as shown in the code above), after passing thru faces servlet both request.getCharacterEncoding() and response.getCharacterEncoding() return "null" and "ISO-8859-1" respectively

I think due to this I am not getting the Japanese character properly in browser as well as in System console.

In order to work I have created a filter and set both the content type and character encoding.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
     response.setContentType("text/html; charset=Shift_JIS");
     request.setCharacterEncoding("Shift_JIS");
     chain.doFilter(request, response);
}
I don't know whether this approach is the right way or something has to be done in faces servlet itself.

I am also seeing another weird problem -- for the JSF command button if the label attribute value is "Go" then in the console I am getting the HTML encoded character (&#22856;&#33391). But the browser automatically convert the encoded character and display Japanese character properly. However, when the label is anything other than "Go" both console as well as browser displays proper Japanese characters.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 12 2005
Added on Nov 26 2003
7 comments
707 views