<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>页面提交中文测试!</h1>
<h2>GET方式</h2>
<a href="/testweb/TestServlet?param=中文">GET方式提交中文测试</a>
<h2>POST方式</h2>
<form action="/testweb/TestServlet" method="post">
<input type="text" name="param" value="中文"/>
<button type="submit" name="提交中文参数测试" value="提交中文参数测试"/>
</form>
</body>
</html>
String x = new String(param.getBytes("ISO-8859-1"), "GBK");
System.out.println("GET方式获取的中文参数值:" + x);
String param = request.getParameter("param");
System.out.println("POST方式获取的中文参数值:" + param);
String x = new String(param.getBytes("ISO-8859-1"), "GBK");
System.out.println("GET方式获取的中文参数值:" + x);
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DealPageParamServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String param = request.getParameter("param");
String x = new String(param.getBytes("ISO-8859-1"), "GBK");
System.out.println("GET方式获取的中文参数值:" + x);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("GBK");
String param = request.getParameter("param");
System.out.println("POST方式获取的中文参数值:" + param);
}
}