在JSP中,如何使用utf8编码获取GET参数?

Yis*_*ang 0 encoding jsp utf-8

我正在使用GlassFish 4,我的JSP文件很简单:

<%@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>
Run Code Online (Sandbox Code Playgroud)

这是我的要求GET index.jsp?a=??,输出是:

åå² 
Run Code Online (Sandbox Code Playgroud)

它出什么问题了?

小智 5

您可以使用此代码"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>
Run Code Online (Sandbox Code Playgroud)