JSP web应用程序开发教程实验二

版权声明:转载请注明出处:http://blog.csdn.net/dajitui2024 https://blog.csdn.net/dajitui2024/article/details/79396229

编码统一utf-8

文件名:e2alert.html

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Conten-Type" content="text/html; charset=UTF-8">
<title>登录失败</title>
</head>
<body>
    <h1 align="center">
        用户名或密码不正确!<br>
        没有登录!无权访问本网站!
    </h1>
    <h1 align="center"><a href="e2login.html">请登录!</a></h1>
</body>
</html>

文件名:e2check_login.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
    <%
        String name=request.getParameter("username");
        String password=request.getParameter("passwd");
        
        if(name.equals("admin") && password.equals("123"))
        {
            session.setAttribute("username",name);
            response.sendRedirect("e2login_success.jsp");
        }
        else
        {
        %>
        <jsp:forward page="e2alert.html"/>
        <%
        }
        %>
</body>
</html>

文件名:e2login.html

<html>
    <body>
        <form method=post action="e2check_login.jsp">
            <table align="center">
                <tr>
                    <td>
                        用户名:
                    </td>
                    <td>
                        <input type=text name="username">
                    </td>
                </tr>
                <tr>
                    <td>
                        密码:
                    </td>
                    <td>
                        <input type=text name="passwd">
                    </td>
                </tr>
                <tr>
                    <td colspan=2 align="center">
                        <input type=submit value="登录">
                            &nbsp;&nbsp;&nbsp;&nbsp;
                            <input type=reset value="重设">
                    </td>
                </tr>
            </table>
    </body>
</html>

文件名:e2login_success.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@include file="e2session_check.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>登录成功</title>
</head>
<body>
    <br>
    <hr width=380>
    <center>
        <h1>
            <%
            out.print(sename);
            %>
            登录成功
        </h1>
        <h2>
            欢迎您!<%=sename %>
        </h2>
    </center>
</body>
</html>

文件名:e2session_check.jsp

<%@ page language="java"  contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
    <%
        String sename=(String)session.getAttribute("username");
    if(sename==null || !sename.equals("admin"))
    {
        response.sendRedirect("e2alert.html");
    }
    %>
</body>
</html>
上一篇:Solaris 10(x86)构建Oracle 10g RAC之--建立数据库


下一篇:第一次使用CSDN-markdown编辑器