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

时间:2013-08-09 15:15:10

标签: jsp encoding 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>

这是我的请求GET index.jsp?a=历史,输出为:

åå² 

它出了什么问题?

1 个答案:

答案 0 :(得分: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>