中文乱码

get 方法:

 
    <%
        request.setCharacterEncoding("UTF-8");
    %>
    
    username: <%= request.getParameter("username") %>

post方法:需要到server.xml中为 Connector 节点添加 useBodyEncodingForURI="true" 属性即可.

<Connector connectionTimeout="20000" port="8989" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true"/>

 

或者对它重新打乱然后拼成;

   String val = request.getParameter("username");
        String username = new String(val.getBytes("UTF-8"), "UTF-8");
        out.print(username);

 

posted @ 2017-03-31 09:33  陆伟  阅读(158)  评论(0编辑  收藏  举报