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
  • 8,880
  • 20
  • 59
  • 100

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