天天看點

JSP web應用程式開發教程實驗二編碼統一utf-8

版權聲明:轉載請注明出處: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>