您的位置:首页 > 其它

编写留言簿的一个问题, 研究了三天了也没看出来哪里不对, 请各位大神给支个招

2015-11-27 17:02 519 查看
程序代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta 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="java.net.URLDecoder" %>
<%@page import="java.net.URLEncoder" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta 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="java.net.URLDecoder" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta 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

各位大神帮帮忙指一下错误吧
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: