• java web 程序---登陆验证session。提示登陆


    loigin.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
    
        
        <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>
      <form action="check.jsp">
      账号: <input type="text" name="user"/><br/>
       密码:<input type="text" name="pass"/><br/>
       <input type="submit" value="登陆"/>
       </form>
      </body>
    </html>

    check.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
    
        
        <title>My JSP 'check.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 name=request.getParameter("user");
        	String pass=request.getParameter("pass");
        	if(name.equals("abc")&&pass.equals("mas")){
        		
        	session.setAttribute("name",name);
        	session.setAttribute("pass",pass);
        	
        	
        	
        	%>
        <jsp:forward page="a.jsp"/>
        <%	}else{
        	out.print("你好,你的输入有误!");
        %>
        		<a href ="login.jsp">重新登陆</a>
        	
        	<%}%>
        
        
         
      </body>
    </html>
    

      a.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
    
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
    
        
        <title>My JSP 'a.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 a=(String)session.getAttribute("name");
            String b=(String)session.getAttribute("pass");
            if(a==null||b==null){%>
            <jsp:forward page="b.jsp"/>
            
            <%}%>
         
         登陆成功
      </body>
    </html>

    b.jsp

    <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
          <title>My JSP 'b.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>
    请先登陆
    <a href="login.jsp">重新登陆</a>
      </body>
    </html>
  • 相关阅读:
    类数组对象与arguments
    bind的模拟实现
    new的模拟实现
    call和apply的模拟实现
    参数按值传递
    闭包
    执行上下文
    ECMAScript规范解读this
    缓存使用-8、redis的缓存穿透和缓存雪崩
    缓存使用-7、Redis 为什么是单线程的
  • 原文地址:https://www.cnblogs.com/langlove/p/3667723.html
Copyright © 2020-2023  润新知