jsp重定向传值,如果值是汉字该怎么办
直接访问第一个页面test1.jsp
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<%
//这是test1.jsp页面
//response.sendRedirect("test2.jsp?uname=robert"); 这个没问题
response.sendRedirect("test2.jsp?uname=罗伯特");//这个在test2.jsp页面没有任何显示,乱码都没
%>
第二个页面test2.jsp
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<%
//这是test2.jsp页面
request.setCharacterEncoding("gbk");
String name=request.getParameter("uname");
out.print(name);
%>
</html>
------解决方案--------------------楼主答案在这里
test1.jsp
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@page import="java.net.URI"%>
<%
//这是test1.jsp页面
String name = "罗伯特";
name = java.net.URLEncoder.encode(name,"gbk");
response.sendRedirect("test2.jsp?uname="+name);
%>
test2.jsp
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body><br>
<%
//这是test2.jsp页面
String name = java.net.URLDecoder.decode(request.getQueryString(),"gbk");
out.println(name.split("\\=")[1]);
%>
</body>
</html>
别忘了给分哦