jsp 页面跳转时 乱码

来源:百度知道 编辑:UC知道 时间:2024/05/29 08:40:31
有2个页面 1.jsp , 2.jsp
从1.jsp跳转到2.jsp.出现乱码.是URL上出现的乱码
1.jsp
String s1 = "java中文乱码";
out.print(s1); //正常
response.sendRedirect("2.jsp?id="+s1);//这样

然后
2.jsp
String s1 = request.getParameter("id");
if(s1 != null)
{
s1 = new String(s1.getBytes("ISO-8859-1"),"GBK");
}
out.print(s1);
////////////////////////////
显示乱码 2.jsp的url上id的值貌似就已经乱了
如果我这样
http://localhost/jsp/2.jsp?id=中文乱码
就能正常显示...
后来加上了
<%@ page contentType="text/html; charset=GBK" pageEncoding="GBK" %>
或者
<%@ page contentType="text/html; charset=GBK" pageEncoding="UTF-8" %>
都不管用... 怎么整的?

2.jsp
String s1 = request.getParameter("id");
if(s1 != null)
{
s1 = new String(s1.getBytes("ISO-8859-1"),"GBK");
}
out.print(s1);
你把条件翻着写看看
if(null != 是1)
{
s1 = new String(s1.getBytes("ISO-8859-1"),"GBK");
}

写个过滤器试试