jspログイン単純インスタンス

4162 ワード

      aaa         ,                 。
 、session_login.html
<html> <body>
<form method=post action="check_login.jsp">
<table>
<tr><td>name:</td><td>
  <input type=text name=name> </td></tr>
<tr><td>password:</td><td> 
  <input type=text name=password> </td></tr>
<tr colspan=2><td>
    :
<input name=type type=radio value=manager checked>
   
<input type=radio name=type value=user>
    
</td></tr>
<tr colspan=2> <td> <input type=submit value=login> </td> </tr>
</table>
</body> </html>
 、check_login.jsp

<%@ page contentType="text/html; charset=gb2312" %>

<%
//  session_login.html      
String name=request.getParameter("name");
String password=request.getParameter("password");
String type=request.getParameter("type");
//          ,          aaa       ,

if(password.equals("aaa")) {
  ///     ,       session  ,
  session.setAttribute("name",name);
  session.setAttribute("password",password);
  session.setAttribute("type",type);
  ///               ,
if(type.equals("manager"))
   response.sendRedirect("manager.jsp");
else if(type.equals("user"))
   response.sendRedirect("user.jsp");
else {
    out.print("<script language='JavaScript' type='text/JavaScript'>alert('  !     !');</script>");
    response.sendRedirect("session_login.html");
}
}
else
//    ,  session_login.html  。
{

out.print("<script>alert('       !');window.location.href='session_login.html'</script>");

//out.print("<script language='JavaScript' type='text/JavaScript'>alert('       !');</script>");
//response.sendRedirect("session_login.html");
}
%>

 、manager.jsp

<%@ page contentType="text/html; charset=gb2312" %>
<%
//  password      ,    session    password            ,

if(session.getAttribute("password")==null)
{out.print("<script>alert('       !');window.location.href='session_login.html'</script>");}
//           session         ,   user                ,         ,

if(session.getAttribute("type")==null||!session.getAttribute("type").equals("manager"))
{out.print("<script>alert('      ,     !');window.location.href='session_login.html'</script>");}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>     </title>

</head>
<body>

       !
</body>
</html>

 、user.jsp

<%@ page contentType="text/html; charset=gb2312" %>
<%
//  password      ,    session    password            ,

if(session.getValue("password")==null)
out.print("<script>alert('      !');window.location.href='session_login.html'</script>");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>    </title>

</head>
<body>

      !
</body>
</html>

 
 
抜粋:http://www.java3z.com/cwbwebhome/article/article5/5538.html?id=751
 
 
怒りのコード