随笔-0  评论-0  文章-16  trackbacks-0
t7.jsp

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<%@ page import="javax.servlet.http.*" %>
<!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=GBK">
<title>Insert title here</title>
</head>
<body>
<%
  String welcome="第一次访问";
  String[] info=new String[]{"","",""};
  Cookie[] cook=request.getCookies();
  if (cook!=null)
  {
   for(int i=0;i<cook.length;i++)
   {
    if (cook[i].getName().equals("myCookInfo"))
    {
     info=cook[i].getValue().split("#");
     welcome=",欢迎回来!";
    }
   }
  }
%>
<%=info[0]+welcome %>
<form action="t8.jsp" method="post">

 

<ul>
<li>
姓名:<input name="name" type="text" value="<%=info[0] %>" >

</li>
<li>
出生日期:<input name="birthday" type="text" value="<%=info[1] %>">


</li>
<li>
邮箱地址:
<input name="mail" type="text" value="<%=info[2] %>" >
</li>
<li>
<input type="submit" value="提交">
</li>
</ul>
</form>

</body>
</html>


t8.jsp
<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!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=GBK">
<title>Insert title here</title>
</head>
<body>
 <%
  String name =new String(request.getParameter("name").getBytes("ISO8859_1"),"GBK");
     String birthday = request.getParameter("birthday");
     String mail = request.getParameter("mail");
     Cookie myCook = new Cookie("myCookInfo",name+"#"+birthday+"#"+mail);
     myCook.setMaxAge(60*60*24*365);
     response.addCookie(myCook);
    %>
    表单提交成功
    <ul style="line-height: 24px">
     <li>姓名:<%= name %>
     <li>出生日期:<%= birthday %>
     <li>电子邮箱:<%= mail %>
     <li><a href="t7.jsp">返回</a>
    </ul>
</body>
</html>
posted on 2012-07-04 14:23 jhtchina 阅读(145) 评论(0)  编辑  收藏 所属分类: jsp初学