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);