zoukankan      html  css  js  c++  java
  • 11月23日学习日志

    今天学习了jsp设置 cookie 。

    main.jsp 文件代码如下所示:

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ page import="java.net.*" %>
    <%
       // 编码,解决中文乱码   
       String str = URLEncoder.encode(request.getParameter("name"),"utf-8");  
       // 设置 name 和 url cookie 
       Cookie name = new Cookie("name",
               str);
       Cookie url = new Cookie("url",
                  request.getParameter("url"));
    
       // 设置cookie过期时间为24小时。
       name.setMaxAge(60*60*24); 
       url.setMaxAge(60*60*24); 
    
       // 在响应头部添加cookie
       response.addCookie( name );
       response.addCookie( url );
    %>
    <html>
    <head>
    <title>设置 Cookie</title>
    </head>
    <body>
    
    <h1>设置 Cookie</h1>
    
    <ul>
    <li><p><b>网站名:</b>
       <%= request.getParameter("name")%>
    </p></li>
    <li><p><b>网址:</b>
       <%= request.getParameter("url")%>
    </p></li>
    </ul>
    </body>
    </html>

    以下是一个简单的 HTML 表单通过 GET 方法将客户端数据提交到 main.jsp 文件中,并设置 cookie:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <form action="main.jsp" method=GET>
    站点名: <input type="text" name="name">
    <br />
    网址: <input type="text" name="url" />
    <input type="submit" value="提交" />
    </form>
    
    </body>
    </html>
  • 相关阅读:
    [转]TeeChart经验总结 5.Axis
    查询
    [转]VS2010安装说明及所有安装出错的解决办法
    [转]游标
    [转]在C#中实现串口通信
    delphi日期的使用
    Http(1)
    表的操作
    存储过程
    CKeditor
  • 原文地址:https://www.cnblogs.com/20193925zxt/p/14160281.html
Copyright © 2011-2022 走看看