• jsp第5次作业


    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>
            <form action="dologin.jsp" method = "post">
                
                姓名:<input type="text" name="uname"/><br/>
                密码:<input type="password" name="upwd"/><br/>
                <input type="submit" value="登录"/><br/>
            </form>
    </body>
    </html>

    dologin.jsp界面:

    <%@page import="javax.websocket.Session"%>
    <%@page import="java.nio.channels.SeekableByteChannel"%>
    <%@ 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>
            <% 
                request.setCharacterEncoding("utf-8");
                String name =request.getParameter("uname");
                String pwd = request.getParameter("upwd");
                if(name.equals("zs")&&pwd.equals("123")){
                    session.setAttribute("uname", name);
                    session.setAttribute("upwd", pwd);
                    request.getRequestDispatcher("Welcome.jsp").forward(request, response);
                }else{
                    response.sendRedirect("login.jsp");
                }
            
            
            %>
    </body>
    </html>

    Welcome.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 = (String)session.getAttribute("uname");
                out.print(name);
            %>
    </body>
    </html>

     

  • 相关阅读:
    [导入]Interesting Finds: 2007.12.17
    [导入]Interesting Finds: 2007.12.15
    [导入]Interesting Finds: 2007.12.13
    Interesting Finds: 2007.12.22
    吾生也有涯,而知也无涯。
    Hello world
    学习了clipboard复制剪切插件的使用
    在博客园学习成长
    命名空间概述
    Linux vi/vim
  • 原文地址:https://www.cnblogs.com/hyonf/p/14641695.html
Copyright © 2020-2023  润新知