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>
    
  • 相关阅读:
    mssql like的效率
    【编辑器开发】基本js指令
    QQ菜单OUTLOOK风格
    oracle exp/imp命令详解
    javascript读取xml
    在c#中调用windows脚本的方法
    oracle常用命令(转)
    有效创建Oracle dblink的两种方式
    oracle 绑定变量(bind variable)
    Oracle备份与恢复
  • 原文地址:https://www.cnblogs.com/houjiie/p/6221155.html
Copyright © 2011-2022 走看看