Reputation: 11457
I created the following jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<%
byte[] oe1 = {-61,-123};
byte[] oe2 = {-123,-61};
byte[] oe3 = "œ".getBytes("UTF-8");
%>
byte[] oe1 = {-61,-123}: '<%=new String(oe1, "UTF-8")%>'<br/>
byte[] oe2 = {-123,-61}: '<%=new String(oe2, "UTF-8")%>'<br/>
byte[] oe3 = "œ".getBytes("UTF-8"): '<%=new String(oe3, "UTF-8")%>'<br/>
oe3[0], oe3[1]: <%=oe3[0]%>, <%=oe3[1]%>
</body>
</html>
Which prints out the following:
byte[] oe1 = {-61,-123}: '�'
byte[] oe2 = {-123,-61}: '??'
byte[] oe3 = "œ".getBytes("UTF-8"): 'œ'
oe3[0], oe3[1]: -61, -123
What am I missing here. Why does oe3 work but not oe1 or oe2. There is probably something going on here with encoding that I do not understand
Upvotes: 3
Views: 305
Reputation: 75986
To add to BalusC answer, the jsp encoding can also be set globally in web.xml file: http://bordet.blogspot.com/2007/09/jsp-page-encoding.html
Upvotes: 2
Reputation: 1109262
Add this to the top of the JSP to let it print characters using UTF-8 and let the browser interpret the response as UTF-8.
<%@ page pageEncoding="UTF-8" %>
The <meta>
tag doesn't do that. Even more, it's ignored when the page is served over HTTP.
Upvotes: 4