由于地址栏会将中文参数编码,因而另一个接受页面获取的参数肯定是乱码。
应先在提交页面将中文参数编码,接受页面解码,如下:
提交页面:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <body> <% String name = "张三"; String tname = URLEncoder.encode(name,"utf-8"); response.sendRedirect("test2.jsp?name="+tname+"&mobile="+"1001"); System.out.print("test2.jsp?name="+tname); %> </body>
接收页面:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <body> <% String name = request.getParameter("name"); name = new String(name.getBytes("ISO-8859-1"),"utf-8"); out.print("name="+name); %> </body>