response.setHeader("refresh","5;url=success.jsp?idname="+id);传递中文参数问题

小弟最近刚学jsp,有个问题一直闹不明白,翻了好久资料也没找到答案。这个题目的要求是输入中文,如果不含有这个中文的话就会跳转到welcome.jsp页面,并且五秒后自动跳转到success.jsp页面,目前只有一个闹不明白,就是welcome.jsp中的response.setHeader("refresh","5;url=success.jsp?send="+str);,传递到success.jsp页面时是乱码,求解。。。。

具体源码如下:

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>a</title>
</head>

<body>
<form action="b.jsp" method="get" name="form1">
    <p>请输入内容: <input type="text" name="fname" /></p>
    <input type="submit" value="Submit" />
   </form>
</body>
</html>

 

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>b</title>
<%!LinkedList listname=new LinkedList();%>
</head>
<body>
<%
String str=request.getParameter("fname");
if(listname.contains(str))
{
%>
<jsp:forward page="fail.jsp"/>
<%
}
else{
listname.add(str);
%>
<jsp:forward page="welcome.jsp">
<jsp:param name="good" value="<%=str%>"/>
</jsp:forward>
<%
}
%>
</body>
</html>

 

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" pageEncoding="gb2312" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>refresh</title>
</head>

<body>
<%
 String str=request.getParameter("good");
 byte b[]=str.getBytes("iso-8859-1");
 str=new String(b,"gb2312");
 %>
 <p>添加<%=str%>成功, 页面将五秒钟实现跳转。</p>
 <%
  response.setHeader("refresh","5;url=success.jsp?send="+str);
 %>
 <p>否则点击<a href="success.jsp?send=<%=str%>">此处跳转</a></p>
</body>
</html>

 

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" pageEncoding="gb2312" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>success</title>
</head>
<body>
<%String str=request.getParameter("send");
 byte b[]=str.getBytes("iso-8859-1");
 str=new String(b,"gb2312");
 %>
创建成功 <%=str%>
</body>
</html>

 

传递url之前,先统一一下编码格式。

改成GBK试试