zoukankan      html  css  js  c++  java
  • Cookie的应用

    作用:在浏览器当中用cookie来保存参数,比如实现登录功能时用来保存账号

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'Login.jsp' starting page</title>
        
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css">
    	-->
    
      </head>
      
      <body>
      <%
      String loginname = "";
      Cookie[] cookies = request.getCookies();
      		if(cookies!=null){
      			for(Cookie cookie : cookies){
      	  			if(cookie.getName().equals("loginname")){
      	  				loginname=cookie.getValue();
      	  				break;
      	  			}
      	  		}
      		}
      		
      %>
      
       <form action="loginapp.jsp" method="post">
       
       用户名 :<input type=text name="username" value="<%=loginname%>" > <br><br>
                    <input type="submit" value="提交">
       </form>
      </body>
    </html>
    
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'Loginapp.jsp' starting page</title>
        
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css">
    	-->
    
      </head>
      
      <body>
       
       <%
       String username = request.getParameter("username");
       
       Cookie c = new Cookie("loginname",username);
       
       response.addCookie(c);
       %>
       
      </body>
    </html>
    
  • 相关阅读:
    uiwebview与objective-c
    ios开发:如何用js调用ios
    ios上ZXing库的配置流程
    IOS连接
    ios开发:如何加载大量图片 相册示例
    ASIHTTPRequest中文入门教程全集 http://www.zpluz.com/thread-3284-1-1.html
    Error message Object BOM does not allow filter on MAST.STLNR
    How to download sales BOM from ERP to CRM
    CRM中间件里parent not ok的错误消息如何处理
    SAP CRM settype的重要性
  • 原文地址:https://www.cnblogs.com/houjiie/p/6221155.html
Copyright © 2011-2022 走看看