隨筆-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" "<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" "
          <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>
          主站蜘蛛池模板: 商河县| 阿拉善左旗| 花垣县| 塔河县| 丰原市| 青铜峡市| 石门县| 山西省| 莱西市| 田东县| 张掖市| 手游| 扬州市| 凌云县| 泾源县| 达拉特旗| 临桂县| 济源市| 五莲县| 辽源市| 卓资县| 曲水县| 独山县| 从化市| 任丘市| 金川县| 南丰县| 柞水县| 垦利县| 黔东| 吴川市| 静宁县| 图们市| 兴仁县| 辽阳县| 长沙县| 石渠县| 铜川市| 体育| 棋牌| 繁峙县|