编写留言簿的一个问题, 研究了三天了也没看出来哪里不对, 请各位大神给支个招
程序代码:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>编辑页面</title> </head> <body> <form action="6.9.2(2).jsp" method="post"> <table> <tr> <td>留言给<input size="10" type="text" value="" name="nm1" /></td> </tr> <tr> <td><textarea rows="10" cols="50" name="nm2"></textarea></td> </tr> <tr> <td><input type="submit" value="提交" /></td> </tr> </table> </form> <form action="6.9.2(3).jsp"><input type="submit" value="显示留言"/></form> </body> </html>
程序代码:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import=" %> <%@page import=" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% request.setCharacterEncoding("UTF-8"); try { String a = request.getParameter("nm1"); String b = request.getParameter("nm2"); if(a==""||a==null||a.length()==0) { out.print("请将姓名填写完整"); } else if(a!="") { Cookie c = new Cookie(a,b); c.setMaxAge(60*60*3); response.addCookie(c); out.print("留言已添加..."); response.setHeader("refresh","3;URL=6.9.2(1).jsp"); } } catch (Exception e) { out.println(e); } %> <form action="6.9.2(1).jsp"><input type="submit" value="写留言" /></form> <form action="6.9.2(3).jsp"><input type="submit" value="显示留言"/></form> </body> </html>
程序代码:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import=" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% request.setCharacterEncoding("UTF-8"); Cookie[] co = request.getCookies(); if(co != null) { for(int i = 0; i<co.length; i++) { out.print("To "+co[i].getName()+"——"+co[i].getValue()); out.print("</br>"); } } %> <form action="6.9.2(1).jsp"><input type="submit" value="写留言" /></form> </body> </html>
我输入"世界", 然后留言内容是"中午饭不回家吃了"
这个运行的时候不能输入中文, 研究了好久好像是转码的问题, 改了好多遍还是这样, 捕捉回来的信息是 java.lang.IllegalArgumentException: Cookie name "世界" is a reserved token
各位大神帮帮忙指一下错误吧...跪谢!