j源码实例5(cookie)_JSP技巧_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

j源码实例5(cookie)

作者:黑客防线网安JSP教程基地 来源:黑客防线网安JSP教程基地 浏览次数:0

本篇关键词:实例源码cookiethat
黑客防线网安网讯:package coreservlets;    import java.io.*;  import javax.servlet.*;  import javax.servlet.http.*;    /** Sets six cookies: three that apply only to the current  *...
package coreservlets;
  
   import java.io.*;
   import javax.servlet.*;
   import javax.servlet.http.*;
  
   /** Sets six cookies: three that apply only to the current
   * session (regardless of how long that session lasts)
   * and three that persist for an hour (regardless of
   * whether the browser is restarted).
   * <P>
   * Taken from Core Servlets and JavaServer Pages
   * from Prentice Hall and Sun Microsystems Press,
   * http://www.coreservlets.com/.
   * &copy; 2000 Marty Hall; may be freely used or adapted.
   */
  
   public class SetCookies extends HttpServlet {
   public void doGet(HttpServletRequest request,
   HttpServletResponse response)
   throws ServletException, IOException {
   for(int i=0; i<3; i++) {
   // Default maxAge is -1, indicating cookie
   // applies only to current browsing session.
   Cookie cookie = new Cookie("Session-Cookie-" + i,
   "Cookie-Value-S" + i);
   response.addCookie(cookie);
   cookie = new Cookie("Persistent-Cookie-" + i,
   "Cookie-Value-P" + i);
   // Cookie is valid for an hour, regardless of whether
   // user quits browser, reboots computer, or whatever.
   cookie.setMaxAge(3600);
   response.addCookie(cookie);
   }
   response.setContentType("text/html");
   PrintWriter out = response.getWriter();
   String title = "Setting Cookies";
   out.println
   (ServletUtilities.headWithTitle(title) +
   "<BODY BGCOLOR="#FDF5E6"> " +
   "<H1 ALIGN="CENTER">" + title + "</H1> " +
   "There are six cookies associated with this page. " +
   "To see them, visit the " +
   "<A HREF="/servlet/coreservlets.ShowCookies"> " +
   "<CODE>ShowCookies</CODE> servlet</A>. " +
   "<P> " +
   "Three of the cookies are associated only with the " +
   "current session, while three are persistent. " +
   "Quit the browser, restart, and return to the " +
   "<CODE>ShowCookies</CODE> servlet to verify that " +
   "the three long-lived ones persist across sessions. " +
   "</BODY></HTML>");
   }
   }
  
    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-16561-1.html
网站维护教程更新时间:2012-04-07 00:43:01  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer