jsp内置对象作业2-留言簿

1.留言簿页面:liuYan.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %> <%@ page import= "java.net.URLDecoder" %> <%@ page import="java.util.*" %>
<!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>
<h3>留言薄</h3>
<%
Cookie[] co = request.getCookies(); String nc = "";
String ly = ""; //ArrayList<String> ar = new ArrayList<>(); if(co != null)
{
for(int i = 0; i < co.length; i++)
{
if(co[i].getName().equals("myco"))
{
//String mes = ""; nc = URLDecoder.decode(co[i].getValue().split("#")[0]); ly = URLDecoder.decode(co[i].getValue().split("#")[1]); //ar.add(mes); out.print("<br>昵称:" + nc +"<br> 留言:" + ly + "<br>");
}
} /*
for(int i = 0; i < ar.size(); i ++)
{
out.print("<br>昵称:" + ar.get(i).split("#") +"<br> 留言:" + ar.get(i).split("#")[1] + "<br>");
}
*/
}
else
{
out.print("暂时没有留言");
}
%>
<br>
<form name = "form2" action = "xianShi.jsp" method="post">
请输入昵称:<input type = "text" name = "nc"><br> 请输入您的留言:<br>
<textarea rows="10" cols="100" name = "ly"></textarea>
<br>
<input type = "submit" value = "提交"> </form>
</body>
</html>

2,留言处理页面, xianShi.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" errorPage="error1.jsp"%> <%@ 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>留言处理页</title>
</head>
<body>
<%
//request.setCharacterEncoding("GB18030"); //String nc = URLEncoder.encode(request.getParameter("nc"),"UTF-8");
String nc = URLEncoder.encode(new String(request.getParameter("nc").getBytes("ISO-8859-1"),"UTF-8"));
String ly = URLEncoder.encode(new String(request.getParameter("ly").getBytes("ISO-8859-1"),"UTF-8")); Cookie co = new Cookie("myco",nc + "#" + ly); co.setMaxAge(60*60*24*30); response.addCookie(co); //out.print(); response.sendRedirect("liuYan.jsp");
%> </body>
</html>
上一篇:整理:FPGA选型


下一篇:EXTJS 6 新特性(译文)