0

I am using GlassFish 4, and my JSP file is simple:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%= request.getParameter("a") %>
    </body>
</html>

This is my request GET index.jsp?a=历史, and the output is:

åå² 

What's wrong with it?

Yishu Fang
  • 9,448
  • 21
  • 65
  • 102
  • 1
    try this <%=request.getParameter("a").getBytes("iso-8859-1"), "UTF-8")%> – Satya Aug 09 '13 at 15:19
  • One of my classmates have found it, but is there is more convient way to change the default encoding of URL into utf8? – Yishu Fang Aug 09 '13 at 15:20
  • check this URL http://stackoverflow.com/questions/1365806/why-the-character-is-corrupted-when-use-request-getparameter-in-java – Satya Aug 09 '13 at 15:21

1 Answers1

5

You can use this code "a_receive = new String(a_receive.getBytes("ISO8859_1"), "UTF-8");"

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <% a_receive = request.getParameter("a") 
           a_receive = new String(a_receive.getBytes("ISO8859_1"), "UTF-8");
%>
        <%=a_receive %>
    </body>
</html>
NuuoeiZ
  • 94
  • 1
  • 4