Jsp 记住密码

index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"
 contentType="text/html; charset=GBK"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + path + "/";
   
 String name = null;
 String pass = null;  
   
 Cookie[] cookies = request.getCookies();
 for (int i = 0; cookies != null && i < cookies.length; i++) {
     if(cookies[i].getName().equals("user")){
      name = cookies[i].getValue().split("-")[0];
      pass = cookies[i].getValue().split("-")[1];
     }
 }  
 if(name == null){
  name = "";
 }
 if(pass == null){
  pass = "";
 }
%>


登录界面


 




  
    
  
  
    
    
  
  
    
    
  
  
   
    
  
    
   
    
  
  
    
    
管理员登录  
    
通行证:
      
    
口令:
      
    
 
        记住密码
    
 
        我同意以上条款
    

         
      
    

  
  
  

 

checkLogin.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
   + request.getServerName() + ":" + request.getServerPort()
   + path + "/";

 String name = request.getParameter("name");
 String pass = request.getParameter("pass");
 String ck = request.getParameter("ck");
 if(ck == null){
  ck = "0";
 }

 if (ck.equals("1")) {
  try {
   Cookie user = new Cookie("user", name + "-" + pass);
   user.setMaxAge(60);
   response.addCookie(user);
  } catch (Exception e) {
   e.printStackTrace();
  }

 }
%>



 
  

  My JSP 'checkLogin.jsp' starting page

  
  
  
  
  
  

 

 
  This is my JSP page.
  

 

 

PS:  直接发布在Tomcat下面 运行即可...

你可能感兴趣的:(jquery,js,页面显示)