jsp对象

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

具体源码如下:

A.jsp代码  
  1. <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head>  
  5. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  6. <title>a</title>  
  7. </head>  
  8.   
  9. <body>  
  10. <form action="b.jsp" method="get" name="form1">  
  11.     <p>请输入内容: <input type="text" name="fname" /></p>  
  12.     <input type="submit" value="Submit" />  
  13.    </form>  
  14. </body>  
  15. </html>  

 

B.jsp代码  
  1. <%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*" errorPage="" %>  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head>  
  5. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  6. <title>b</title>  
  7. <%!LinkedList listname=new LinkedList();%>  
  8. </head>  
  9. <body>  
  10. <%  
  11. String str=request.getParameter("fname");  
  12. if(listname.contains(str))  
  13. {  
  14. %>  
  15. <jsp:forward page="fail.jsp"/>  
  16. <%  
  17. }  
  18. else{  
  19. listname.add(str);  
  20. %>  
  21. <jsp:forward page="welcome.jsp">  
  22. <jsp:param name="good" value="<%=str%>"/>  
  23. </jsp:forward>  
  24. <%  
  25. }  
  26. %>  
  27. </body>  
  28. </html>  

 

Welcome.jsp代码  
  1. <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" pageEncoding="gb2312" errorPage="" %>  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head>  
  5. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  6. <title>refresh</title>  
  7. </head>  
  8.   
  9. <body>  
  10. <%  
  11.  String str=request.getParameter("good");  
  12.  byte b[]=str.getBytes("iso-8859-1");  
  13.  str=new String(b,"gb2312");  
  14.  %>  
  15.  <p>添加<%=str%>成功, 页面将五秒钟实现跳转。</p>  
  16.  <%  
  17.   response.setHeader("refresh","5;url=success.jsp?send="+str);  
  18.  %>  
  19.  <p>否则点击<a href="success.jsp?send=<%=str%>">此处跳转</a></p>  
  20. </body>  
  21. </html>  

 

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

 

posted @ 2013-08-20 13:38  最是那一杯红酒  阅读(124)  评论(0编辑  收藏  举报