码迷,mamicode.com
首页 > Web开发 > 详细

JSP DAO(Model)

时间:2019-01-06 11:58:50      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:response   request   prope   用户名   ebe   bean   pre   charset   users   

示例代码:

1. Users类

package com.po;

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;
    }
}

2. DAO类

package com.dao;

import com.po.Users;

public class UsersDAO {

    // 用户登录方法
    public boolean usersLogin(Users u){
        return ("admin".equals(u.getUsername()) && "admin".equals(u.getPassword()));
    }
}

3. HTML代码

<%@ page contentType="text/html;charset=UTF-8" %>
<jsp:useBean id="loginUser" class="com.po.Users" />
<jsp:useBean id="userDAO" class="com.dao.UsersDAO" />
<jsp:setProperty name="loginUser" property="*" />

<%
    // 如果用户名和密码都等于admin,则登录成功
    if(userDAO.usersLogin(loginUser)){
        session.setAttribute("loginUser", loginUser.getUsername());
        request.getRequestDispatcher("login_success.jsp").forward(request, response);
    }else {
        response.sendRedirect("login_failure.jsp");
    }
%>

 

JSP DAO(Model)

标签:response   request   prope   用户名   ebe   bean   pre   charset   users   

原文地址:https://www.cnblogs.com/vincenshen/p/10227582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!