i 绝望

依然

Miss Lang

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>

 

posted on 2014-04-16 00:01  juewang  阅读(378)  评论(0编辑  收藏  举报

绝望依然

Miss Lang