• 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>

     

  • 相关阅读:
    插入排序java代码
    选择排序java代码
    break语句的作用
    while和do-while的区别
    if-else-if-else与switch的区别
    Java中基本类型的转换规则
    如何让计算机最高效的算出2乘以8?
    |和||的作用和区别
    &和&&的作用和区别
    i++和++i的作用和区别
  • 原文地址:https://www.cnblogs.com/hyonf/p/14641695.html
Copyright © 2020-2023  润新知