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

编码统一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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,131评论 19 139
  • 1.什么是JSP (1)jsp全称是Java Server Pages,它和Servlet技术一样都是sun公司定...
    yjaal阅读 3,701评论 5 99
  • 编码统一utf-8 文件名:a.jsp 文件名:b.jsp 文件名:ex201.jsp 文件名:test1.jsp...
    一点也不想吃辣阅读 222评论 0 0
  • 情到,深处,则无语 爱到,深处,不隐藏 细雨,打湿了我的面庞 泪花,泛起在我的眼眶 姑娘,消失到我的远方 听,地上...
    采昔阅读 191评论 0 2
  • 灯光炫目得很,映衬着皮肤几近透明,似乎看见每毛孔在呼吸。他们彼此沉默,空气里弥漫着腾起的米香,但丝毫激不起食欲,吃...
    桃子满满阅读 176评论 0 0