国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

JavaEE 課堂案例: 簡(jiǎn)單實(shí)現(xiàn)登錄功能: 1.前端用戶(hù)自己輸入賬號(hào)密碼, 點(diǎn)擊登錄 2.服務(wù)器端獲得賬號(hào)密碼, 數(shù)據(jù)庫(kù)查詢(xún) jar JdbcTemplate 3.登錄成功 -> 跳轉(zhuǎn)到首頁(yè)

這篇具有很好參考價(jià)值的文章主要介紹了JavaEE 課堂案例: 簡(jiǎn)單實(shí)現(xiàn)登錄功能: 1.前端用戶(hù)自己輸入賬號(hào)密碼, 點(diǎn)擊登錄 2.服務(wù)器端獲得賬號(hào)密碼, 數(shù)據(jù)庫(kù)查詢(xún) jar JdbcTemplate 3.登錄成功 -> 跳轉(zhuǎn)到首頁(yè)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

1 首先導(dǎo)入jar包(看個(gè)人情況導(dǎo)入)

?? javaee實(shí)現(xiàn)一個(gè)用戶(hù)注冊(cè)/登錄模塊,數(shù)據(jù)庫(kù),java-ee

?這里需要注意的是平時(shí)我們導(dǎo)入jar包是導(dǎo)入在自己的工程或者moudle下面的,在這里我們必須把jar包導(dǎo)入在WEB-INF中(詳情可看圖),從圖中可看出,一個(gè)工程在編譯過(guò)后,只有src下的數(shù)據(jù)會(huì)編譯到WEB-INF下的classes目錄中,所以需要將靜態(tài)資源,jar包等資源放到web或者WEB-INF中。

javaee實(shí)現(xiàn)一個(gè)用戶(hù)注冊(cè)/登錄模塊,數(shù)據(jù)庫(kù),java-ee

???????????????????????????????????????????????????? 應(yīng)用與項(xiàng)目的關(guān)系

2 連接數(shù)據(jù)庫(kù),我們可以先導(dǎo)入配置文件utils(自己寫(xiě)的druid連接池)

javaee實(shí)現(xiàn)一個(gè)用戶(hù)注冊(cè)/登錄模塊,數(shù)據(jù)庫(kù),java-ee

public class DruidUtils {
   private static DataSource ds;
   static {
       Properties pro = new Properties();
       try {//1.加載配置文件
           pro.load(DruidUtils.class.getResourceAsStream("jdbc.properties"));
           //.2.獲取DataSource
           ds = DruidDataSourceFactory.createDataSource(pro);
       } catch (Exception e) {
           throw new RuntimeException(e);
       }
   }//獲取連接
   public static Connection getConnection() throws SQLException {
       return ds.getConnection();
   }
    //獲取連接池方法
   public static DataSource getDataSource(){
       return ds;
   }
   //釋放資源
   public static void close(Connection conn, PreparedStatement stmt, ResultSet rs){
       try {
           if (rs == null)  rs.close();
           if (stmt == null) rs.close();
           if (conn == null) rs.close();
       } catch (SQLException e) {
           throw new RuntimeException(e);
       }

   }

}

?編寫(xiě)配置文件(僅供參考,要注意的是末尾的.properties后綴名不能寫(xiě)錯(cuò))

driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql:///wyb?serverTimezone=GMT
username=root
password=gg791480

3.編寫(xiě)登錄代碼:

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        JdbcTemplate template = new JdbcTemplate(DruidUtils.getDataSource());
        String sql = "select * from user where name=? and poaaword=?";
        try {
            User user = template.queryForObject(sql,new BeanPropertyRowMapper<>(User.class),username,password);
            response.sendRedirect(request.getContextPath()+"index.jsp");
        }catch (Exception e){
            response.sendRedirect(request.getContextPath()+"/html/loser.html");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}

4.接下來(lái)我們用Java的三層架構(gòu)規(guī)范來(lái)實(shí)現(xiàn)功能

4.1 首先用三成架構(gòu)的方式分析登錄功能,如果所示,我們?cè)趙eb包下實(shí)現(xiàn)獲取參數(shù),發(fā)送請(qǐng)求,service包下處理數(shù)據(jù),dao包下連接數(shù)據(jù)庫(kù)

javaee實(shí)現(xiàn)一個(gè)用戶(hù)注冊(cè)/登錄模塊,數(shù)據(jù)庫(kù),java-ee

4.2如圖,我們?cè)趕rc下創(chuàng)建一個(gè)包,然后再包下再創(chuàng)建如下包

javaee實(shí)現(xiàn)一個(gè)用戶(hù)注冊(cè)/登錄模塊,數(shù)據(jù)庫(kù),java-eejavaee實(shí)現(xiàn)一個(gè)用戶(hù)注冊(cè)/登錄模塊,數(shù)據(jù)庫(kù),java-ee

?web層下代碼:

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    private UserSerivce userSerivce =new UserSerivceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        try {
            User loginUser = userSerivce.login(username, password);
            request.getSession().setAttribute("user",loginUser);
            response.sendRedirect(request.getContextPath()+"/index.jsp");
        }catch (Exception e){
            request.setAttribute("error",e.getMessage());
            request.getRequestDispatcher("/login.jsp").forward(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}

test層(測(cè)試代碼用)

utils層(編寫(xiě)配置文件,與上述一致)

service層代碼(一般會(huì)先寫(xiě)一個(gè)接口,然后再實(shí)現(xiàn)其接口

public interface UserSerivce {
    User login(String username, String password) throws Exception;
}

)

public class UserSerivceImpl implements UserSerivce {
    private UserDao userDao = new UserDaoImpl();
    @Override
    public User login(String username,String password) throws Exception {
        User user = userDao.findByUsernameAndPassword(username, password);
        if (user == null) {
            throw new Exception("登錄或密碼錯(cuò)誤");
        }
        return user;
    }
}

domain成代碼(通過(guò)是寫(xiě)實(shí)體類(lèi))

public class User {
    private Integer id;
    private String name;
    private Integer password;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getPassword() {
        return password;
    }

    public void setPassword(Integer password) {
        this.password = password;
    }
}

dao層(連接數(shù)據(jù)庫(kù)代碼)

public interface UserDao {
    User findByUsernameAndPassword(String username, String password);
}
public class UserDaoImpl implements UserDao {
    private JdbcTemplate template = new JdbcTemplate(DruidUtils.getDataSource());
    @Override
    public User findByUsernameAndPassword(String username,String password){
        String sql = "select * from user where name=? and possword=?";
        List<User> list = template.query(sql, new BeanPropertyRowMapper<>(User.class), username, password);
        return list.size() == 0 ? null : list.get(0);
    }
}

4.3 登錄頁(yè)面(login.jsp,參考)文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-775758.html

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="${pageContext.request.contextPath}/login" method="post">
    用戶(hù)名<input type="text" name="username"><br>
    密碼<input type="password" name="password"><br>
    <sp>${error}</sp>
    <input type="submit" value="登錄">
</form>
</body>
</html>

到了這里,關(guān)于JavaEE 課堂案例: 簡(jiǎn)單實(shí)現(xiàn)登錄功能: 1.前端用戶(hù)自己輸入賬號(hào)密碼, 點(diǎn)擊登錄 2.服務(wù)器端獲得賬號(hào)密碼, 數(shù)據(jù)庫(kù)查詢(xún) jar JdbcTemplate 3.登錄成功 -> 跳轉(zhuǎn)到首頁(yè)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀(guān)點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 9. 實(shí)現(xiàn)業(yè)務(wù)功能--用戶(hù)登錄

    9. 實(shí)現(xiàn)業(yè)務(wù)功能--用戶(hù)登錄

    目錄 1. 順序圖? 2. 參數(shù)要求 3. 創(chuàng)建 Service 接口 4. 實(shí)現(xiàn) Service 接口 5. 單體測(cè)試 6. 實(shí)現(xiàn) Controller? 7. 實(shí)現(xiàn)前端 在用戶(hù)登錄部分特別注意的是需要進(jìn)行密碼校驗(yàn): 1. MD5(MD5(用戶(hù)提交的原密碼)+數(shù)據(jù)庫(kù)查出來(lái)的用戶(hù)的鹽)= 密碼的密文 2. 用上面的生成的密碼的密文和數(shù)據(jù)庫(kù)中用戶(hù)

    2024年02月12日
    瀏覽(19)
  • Java Web實(shí)現(xiàn)用戶(hù)登錄功能

    Java Web實(shí)現(xiàn)用戶(hù)登錄功能

    登錄頁(yè)面login.jsp,輸入用戶(hù)名和密碼后,跳轉(zhuǎn)到登錄處理頁(yè)面doLogin.jsp進(jìn)行業(yè)務(wù)邏輯處理,登錄成功,跳轉(zhuǎn)到登錄成功頁(yè)面success.jsp,否則跳轉(zhuǎn)到登錄失敗頁(yè)面failure.jsp。 (二)實(shí)現(xiàn)步驟 1、創(chuàng)建Web項(xiàng)目 創(chuàng)建 Java Enterprise 項(xiàng)目,添加Web Application功能 設(shè)置項(xiàng)目名與保存位置 單擊

    2024年02月08日
    瀏覽(21)
  • 純JSP方式實(shí)現(xiàn)用戶(hù)登錄功能

    純JSP方式實(shí)現(xiàn)用戶(hù)登錄功能

    (一)實(shí)現(xiàn)思路 登錄頁(yè)面login.jsp,輸入用戶(hù)名和密碼后,跳轉(zhuǎn)到登錄處理頁(yè)面doLogin.jsp進(jìn)行業(yè)務(wù)邏輯處理,登錄成功,跳轉(zhuǎn)到登錄成功頁(yè)面success.jsp,否則跳轉(zhuǎn)到登錄失敗頁(yè)面failure.jsp。 (二)實(shí)現(xiàn)步驟 1、創(chuàng)建Web項(xiàng)目 開(kāi)始先創(chuàng)建 Java Enterprise 項(xiàng)目,添加 Web Application 功能 設(shè)置

    2024年02月08日
    瀏覽(17)
  • 使用SSM框架實(shí)現(xiàn)用戶(hù)登錄功能

    使用SSM框架實(shí)現(xiàn)用戶(hù)登錄功能

    客戶(hù)端有非空校驗(yàn) 登錄成功,跳轉(zhuǎn)到主頁(yè)面 登錄失敗,再次跳轉(zhuǎn)到登錄頁(yè)面 1、創(chuàng)建數(shù)據(jù)庫(kù) 執(zhí)行命令: CREATE DATABASE ssmdb CHARSET=\\\'utf8mb4\\\'; 查看新建的數(shù)據(jù)庫(kù) 2、創(chuàng)建用戶(hù)表? ?執(zhí)行SQL命令生成新的用戶(hù)表 t_user ?3、添加多條用戶(hù)記錄表 運(yùn)行SQL命令,添加4條記錄? ?(二)創(chuàng)建

    2024年02月06日
    瀏覽(17)
  • 【企業(yè)微信開(kāi)發(fā)流程前端篇】企業(yè)微信自建應(yīng)用開(kāi)發(fā)流程詳細(xì)介紹,js-sdk獲取用戶(hù)信息,快捷回復(fù),授權(quán),發(fā)送朋友圈功能實(shí)現(xiàn)【一次看懂,簡(jiǎn)單開(kāi)發(fā)】

    【企業(yè)微信開(kāi)發(fā)流程前端篇】企業(yè)微信自建應(yīng)用開(kāi)發(fā)流程詳細(xì)介紹,js-sdk獲取用戶(hù)信息,快捷回復(fù),授權(quán),發(fā)送朋友圈功能實(shí)現(xiàn)【一次看懂,簡(jiǎn)單開(kāi)發(fā)】

    最近剛好遇到了這么個(gè)任務(wù) 需要我在企業(yè)微信中內(nèi)嵌一個(gè)自建應(yīng)用, 用于打通跟我們醫(yī)院后臺(tái)系統(tǒng)的數(shù)據(jù)對(duì)接。 這樣就可以直接讓客服們?cè)谄髽I(yè)微信上點(diǎn)擊右邊頁(yè)面操作后臺(tái)的數(shù)據(jù)了。 這可是給我踩了好多坑。畢竟從來(lái)沒(méi)有做過(guò)企業(yè)微信的開(kāi)發(fā),有點(diǎn)懵。 也是踩了好多坑

    2024年02月11日
    瀏覽(88)
  • Java開(kāi)發(fā):實(shí)現(xiàn)用戶(hù)注冊(cè)登錄的功能

    Java開(kāi)發(fā):實(shí)現(xiàn)用戶(hù)注冊(cè)登錄的功能

    一、前言 在Java開(kāi)發(fā)過(guò)程中,實(shí)現(xiàn)用戶(hù)的注冊(cè)功能是最基本的,用戶(hù)通過(guò)手機(jī)號(hào)或者郵箱作為注冊(cè)賬號(hào)也是非常常見(jiàn)的操作方式,不管是通過(guò)手機(jī)號(hào)注冊(cè)或者郵箱注冊(cè),原理都差不多,那么本文就來(lái)分享一下在Java開(kāi)發(fā)過(guò)程中的用戶(hù)注冊(cè)賬號(hào)的功能實(shí)現(xiàn)。 二、準(zhǔn)備工作 1、通過(guò)

    2023年04月09日
    瀏覽(24)
  • Python簡(jiǎn)單實(shí)現(xiàn)登錄功能

    代碼如下 代碼講解 1. 意思:導(dǎo)入時(shí)間庫(kù) 2. 意思:自定義用戶(hù)名 3. 意思:自定義密碼 4. 意思:用戶(hù)輸入次數(shù),初始為0 5. 意思:Python的while循環(huán) 6-7. 意思:記錄用戶(hù)輸入的用戶(hù)名和密碼 8-15. 意思:判斷用戶(hù)輸入的用戶(hù)名和密碼是否正確,如果不正確打印密碼或用戶(hù)名錯(cuò)誤,然后a加1如果輸入

    2024年02月11日
    瀏覽(23)
  • MVC框架實(shí)現(xiàn)用戶(hù)登錄注冊(cè)功能(連接數(shù)據(jù)庫(kù))

    MVC框架實(shí)現(xiàn)用戶(hù)登錄注冊(cè)功能(連接數(shù)據(jù)庫(kù))

    一、簡(jiǎn)單理解MVC框架 二、項(xiàng)目結(jié)構(gòu) 三、項(xiàng)目源碼 3.1 User 3.2?UserDao 3.3?RegisterDao 3.4?servletControll 3.5 servletControllRegister 3.6?web.xml 3.7?login.jsp 3.8?register.jsp 3.9?success.jsp 3.10?failure.jsp ?四、實(shí)現(xiàn)效果 總結(jié) 本篇文章主要介紹利用MVC框架去實(shí)現(xiàn)一個(gè)簡(jiǎn)單的用戶(hù)登錄注冊(cè)功能,內(nèi)容主

    2024年02月06日
    瀏覽(38)
  • 微信小程序?qū)崿F(xiàn)簡(jiǎn)單登錄界面和登錄功能

    微信小程序?qū)崿F(xiàn)簡(jiǎn)單登錄界面和登錄功能

    客戶(hù)端開(kāi)發(fā)和學(xué)習(xí)過(guò)程中,登錄功能是一個(gè)很常見(jiàn)的場(chǎng)景。本文將介紹,微信小程序開(kāi)發(fā)過(guò)程中是如何實(shí)現(xiàn)登錄界面和登錄功能的。 話(huà)不多說(shuō),直接上代碼。 (1)index.js文件,代碼如下: (2)index.wxml文件,代碼如下: (3)index.wxss文件,代碼如下: 運(yùn)行結(jié)果如下: 本文介紹了微信

    2024年02月12日
    瀏覽(360)
  • 用Java代碼實(shí)現(xiàn)學(xué)生管理系統(tǒng)(可實(shí)現(xiàn)用戶(hù)登錄注冊(cè)功能)

    用Java代碼實(shí)現(xiàn)學(xué)生管理系統(tǒng)(可實(shí)現(xiàn)用戶(hù)登錄注冊(cè)功能)

    簡(jiǎn)單實(shí)現(xiàn)學(xué)生系統(tǒng)的登錄和注冊(cè),以及學(xué)生信息添加、刪除,修改、查詢(xún)功能。根據(jù)需求,創(chuàng)建一個(gè)學(xué)生類(lèi)和和用戶(hù)類(lèi)以及學(xué)生系統(tǒng)類(lèi),在登錄管理系統(tǒng)之前需要先注冊(cè)用戶(hù),只有輸入正確的用戶(hù)名和密碼才可以登錄,忘記密碼后可以根據(jù)用戶(hù)信息進(jìn)行修改,用容器存儲(chǔ)學(xué)生

    2024年02月05日
    瀏覽(23)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包