zoukankan      html  css  js  c++  java
  • jsp+javabean实现简单的用户登陆

    1:简单的登陆界面的绘制

    <div class="login">
            <form action="doLogin.jsp" method="post">
                <tr>
                    <td>username</td>
                    <td><input type="text" name="username" value="">
                    </td>
                </tr>
                <br>
                <tr>
                    <td>password</td>
                    <td><input type="password" name="password" value="">
                    </td>
                </tr>
                <br>
                <tr>
                    <td colspan=2 align="center"><input type="submit" value="login">
                    </td>
                </tr>
            </form>
        </div>

    2:建立javabean用户类

    package com.entity;
    //登陆的用户类
    public class Users {
    
        private String username;
        private String password;
        public Users(){
            
        }
        public String getUsername() {
            return username;
        }
        public void setUsername(String username) {
            this.username = username;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }
        
        
    }

    3:建立处理业务逻辑的javabean

    package com.dao;
    import com.entity.Users;
    //用户的业务逻辑类
    public class UserDAO {
        //用户登陆方法
        public boolean UserLogin(Users u)
        {
          if("admin".equals(u.getPassword())&&"admin".equals(u.getPassword()))
          {
              return true;
          }
          else
          {
              return false;
          }
        }
    }

    4:对输入登陆账号密码的管理

    <%@ page language="java" import="java.util.*"
        contentType="text/html; charset=utf-8"%>
    <%
        request.setCharacterEncoding("utf-8");
    %>
    <jsp:useBean id="loginUser" class="com.entity.Users" scope="page"></jsp:useBean>
    <jsp:useBean id="UserDAO" class="com.dao.UserDAO" scope="page"></jsp:useBean>
    <jsp:setProperty property="*" name="loginUser" />
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://"
                + request.getServerName() + ":" + request.getServerPort()
                + path + "/";
    
        if (UserDAO.UserLogin(loginUser)) {
            session.setAttribute("loginusername", loginUser.getUsername());
            request.getRequestDispatcher("login_success.jsp").forward(
                    request, response);
            //请求重定向,成功后跳到的是dologin.jsp页面,客户端行为,相当于两次请求
        } else {
            response.sendRedirect("login_failure.jsp");
            //请求转发,成功后跳转到login_failure.jsp页面,服务端行为,相当于一次请求
        }
    %>
  • 相关阅读:
    数据可视化基础专题(九):Matplotlib 基础(一)坐标相关
    PrinterInfo (API: Objects) – Electron 中文开发手册
    Java中的多线程
    简介 (Service Worker) – Angular 中文开发手册
    :不确定 | :indeterminate (Basic User Interface)
    高度 | height (Basic Box Model)
    高度 | @viewport.height (Device Adaptation)
    高度 | @media.height (Media Queries)
    首字 | initial-letter (Inline Layout)
    颜色索引 | @media.color-index (Media Queries)
  • 原文地址:https://www.cnblogs.com/linhong/p/4259982.html
Copyright © 2011-2022 走看看