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

一個(gè)簡(jiǎn)單的前后端交互——登錄注冊(cè)頁(yè)面(升級(jí)版)idea代碼篇(2:Maven:Javaweb項(xiàng)目)使用MyBatis:Mapper,servlet+Tomcat

這篇具有很好參考價(jià)值的文章主要介紹了一個(gè)簡(jiǎn)單的前后端交互——登錄注冊(cè)頁(yè)面(升級(jí)版)idea代碼篇(2:Maven:Javaweb項(xiàng)目)使用MyBatis:Mapper,servlet+Tomcat。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

前言:本篇前后端交互實(shí)現(xiàn)代碼 。詳細(xì)項(xiàng)目搭建見上篇

先貼一張登錄界面和包結(jié)構(gòu):

一個(gè)簡(jiǎn)單的前后端交互——登錄注冊(cè)頁(yè)面(升級(jí)版)idea代碼篇(2:Maven:Javaweb項(xiàng)目)使用MyBatis:Mapper,servlet+Tomcat

一個(gè)簡(jiǎn)單的前后端交互——登錄注冊(cè)頁(yè)面(升級(jí)版)idea代碼篇(2:Maven:Javaweb項(xiàng)目)使用MyBatis:Mapper,servlet+Tomcat

?

一、代碼:

1.Mapper

public interface UserMapper {

    /**
     * 根據(jù)用戶名和密碼查詢用戶對(duì)象
     * @param username
     * @param password
     * @return
     */
    @Select("select * from tb_user where username = #{username} and password = #{password}")
    User select(@Param("username") String username,@Param("password")  String password);



    /**
     * 根據(jù)用戶名查詢用戶對(duì)象
     * @param username
     * @return
     */
    @Select("select * from tb_user where username = #{username}")
    User selectByUsername(String username);

    /**
     * 添加用戶
     * @param user
     */
    @Insert("insert into tb_user values(null,#{username},#{password})")
    void add(User user);}

2.pojo

public class User {

    private Integer id;
    private String username;
    private String password;

    public Integer getId() {
        return id;
    }

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

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

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}

3.util

public class SqlSessionFactoryUtils {

    private static SqlSessionFactory sqlSessionFactory;

    static {
        //靜態(tài)代碼塊會(huì)隨著類的加載而自動(dòng)執(zhí)行,且只執(zhí)行一次

        try {
            String resource = "mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static SqlSessionFactory getSqlSessionFactory(){
        return sqlSessionFactory;
    }
}

4.web


@WebServlet("/loginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1. 接收用戶名和密碼
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        //2. 調(diào)用MyBatis完成查詢
        //2.1 獲取SqlSessionFactory對(duì)象
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);


        //2.2 獲取SqlSession對(duì)象
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //2.3 獲取Mapper
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        //2.4 調(diào)用方法
        User user = userMapper.select(username, password);
        //2.5 釋放資源
        sqlSession.close();


        //獲取字符輸出流,并設(shè)置content type
        response.setContentType("text/html;charset=utf-8");
        PrintWriter writer = response.getWriter();
        //3. 判斷user釋放為null
        if(user != null){
            // 登陸成功
          writer.write("登陸成功");
          
        }else {
            // 登陸失敗
            writer.write("登陸失敗");
        }
    }

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

5.Login.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>login</title>
    <link href="css/login.css" rel="stylesheet">
</head>

<body>
<div id="loginDiv">
    <form action="loginServlet" method="post" id="form">
        <h1 id="loginMsg">登錄</h1>
        <p>Username:<input id="username" name="username" type="text"></p>

        <p>Password:<input id="password" name="password" type="password"></p>

        <div id="subDiv">
            <input type="submit" class="button" value="login up">
            <input type="reset" class="button" value="reset">&nbsp;&nbsp;&nbsp;
<!--            <a href="register.html">沒有賬號(hào)?點(diǎn)擊注冊(cè)</a>-->  
        </div>
    </form>
</div>

</body>
</html>

6.CSS

* {
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    width: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
    background: url(../imgs/img.png) no-repeat 0px 0px;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    -moz-background-size: 100% 100%;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

#loginDiv {
    width: 37%;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 300px;
    background-color: rgba(75, 81, 95, 0.3);
    box-shadow: 7px 7px 17px rgba(52, 56, 66, 0.5);
    border-radius: 5px;
}

#name_trip {
    margin-left: 50px;
    color: red;
}

p {
    margin-top: 30px;
    margin-left: 20px;
    color: azure;
}

input {
    margin-left: 15px;
    border-radius: 5px;
    border-style: hidden;
    height: 30px;
    width: 140px;
    background-color: rgba(216, 191, 216, 0.5);
    outline: none;
    color: #f0edf3;
    padding-left: 10px;
}
#username{
    width: 200px;
}
#password{
    width: 202px;
}
.button {
    border-color: cornsilk;
    background-color: rgba(100, 149, 237, .7);
    color: aliceblue;
    border-style: hidden;
    border-radius: 5px;
    width: 100px;
    height: 31px;
    font-size: 16px;
}

#subDiv {
    text-align: center;
    margin-top: 30px;
}
#loginMsg{
    text-align: center;color: aliceblue;
}

二、總結(jié)

我的企業(yè)版過(guò)期了,不能演示跳轉(zhuǎn)頁(yè)面了。但測(cè)過(guò)沒問(wèn)題。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-503036.html

到了這里,關(guān)于一個(gè)簡(jiǎn)單的前后端交互——登錄注冊(cè)頁(yè)面(升級(jí)版)idea代碼篇(2:Maven:Javaweb項(xiàng)目)使用MyBatis:Mapper,servlet+Tomcat的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(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)文章

  • Flask+Pycharm(專業(yè)版)+mysql編寫一個(gè)簡(jiǎn)單登錄注冊(cè)頁(yè)面

    Flask+Pycharm(專業(yè)版)+mysql編寫一個(gè)簡(jiǎn)單登錄注冊(cè)頁(yè)面

    1.1 存放 1.2 數(shù)據(jù)庫(kù) 博主建立了一個(gè)名為 cat1 的數(shù)據(jù)庫(kù),表名為 students students中的具體內(nèi)容如下: ? ? model 文件夾下的 loginc.py 文件(其中連接數(shù)據(jù)庫(kù)的部分要修改成自己的用戶名和密碼) model 文件夾下的 regist.py 文件(其中連接數(shù)據(jù)庫(kù)的部分要修改成自己的用戶名和密碼)

    2024年02月06日
    瀏覽(23)
  • HTML實(shí)現(xiàn)簡(jiǎn)單注冊(cè)登錄頁(yè)面

    HTML實(shí)現(xiàn)簡(jiǎn)單注冊(cè)登錄頁(yè)面

    以下兩個(gè)頁(yè)面均只用HTML實(shí)現(xiàn)(其中注冊(cè)若要添加號(hào)碼與后面的登錄密碼判斷,涉及到j(luò)avascript的內(nèi)容,本文只使用了html,后續(xù)會(huì)加上這些內(nèi)容) 簡(jiǎn)單注冊(cè):(讀者可以自行增加圖片以及其他屬性) 登錄: ? ?

    2024年02月11日
    瀏覽(22)
  • 前端注冊(cè)登錄頁(yè)面數(shù)據(jù)庫(kù)交互(h5+css+php+mysql+axios)

    前端注冊(cè)登錄頁(yè)面數(shù)據(jù)庫(kù)交互(h5+css+php+mysql+axios)

    一個(gè)登錄注冊(cè)界面,并使用前端數(shù)據(jù)庫(kù)實(shí)現(xiàn)登陸注冊(cè)功能? 首先是index.html 直接在index.html里面寫了用axios,實(shí)現(xiàn)注冊(cè)和登錄 效果圖 登錄注冊(cè)滑動(dòng)實(shí)現(xiàn) script.js style.css 然后是登錄和注冊(cè)的php login.php register.php

    2024年02月11日
    瀏覽(21)
  • Android studio 編寫一個(gè)登錄頁(yè)面,并且具有注冊(cè)功能

    Android studio 編寫一個(gè)登錄頁(yè)面,并且具有注冊(cè)功能

    1、創(chuàng)建登錄界面,點(diǎn)擊注冊(cè)按鈕,彈出注冊(cè)窗口。 2、創(chuàng)建注冊(cè)窗口,輸入用戶名和密碼,在SQLite中存儲(chǔ)用戶名和密碼。 3、注冊(cè)成功,跳轉(zhuǎn)到登錄界面,進(jìn)行登錄。 4、注冊(cè)成功,把用戶名和密碼保存到SharedPreferences中,登錄時(shí)自動(dòng)填充用戶名和密碼。 ??????????登錄頁(yè)

    2023年04月08日
    瀏覽(21)
  • HTML寫一個(gè)簡(jiǎn)單的登錄注冊(cè)界面

    HTML寫一個(gè)簡(jiǎn)單的登錄注冊(cè)界面

    希望對(duì)你們有所幫助,再此感謝各位讀者的支持,再次感謝?。?!?

    2024年02月12日
    瀏覽(17)
  • qt設(shè)計(jì)一個(gè)簡(jiǎn)單的注冊(cè)登錄界面

    qt設(shè)計(jì)一個(gè)簡(jiǎn)單的注冊(cè)登錄界面

    實(shí)現(xiàn)代碼:

    2024年02月14日
    瀏覽(20)
  • Unity制作一個(gè)簡(jiǎn)單的登入注冊(cè)頁(yè)面

    Unity制作一個(gè)簡(jiǎn)單的登入注冊(cè)頁(yè)面

    1.創(chuàng)建Canvas組件 首先我們創(chuàng)建一個(gè)Canvas畫布,我們?cè)僭贑anvas畫布底下創(chuàng)建一個(gè)空物體,取名為Resgister。把空物體的錨點(diǎn)設(shè)置為全屏撐開。 ?2.我們?cè)赗esgister空物體底下創(chuàng)建一個(gè)Image組件,改名為bg。我們也把它 的錨點(diǎn)設(shè)置為全屏撐開狀態(tài)。接下來(lái)我們把我們的圖片UI素材導(dǎo)入進(jìn)

    2024年02月12日
    瀏覽(25)
  • 使用QT制作一個(gè)簡(jiǎn)單的登錄-注冊(cè)界面

    使用QT制作一個(gè)簡(jiǎn)單的登錄-注冊(cè)界面

    1、作業(yè)需求 ? 2、實(shí)現(xiàn)過(guò)程 1)Widget.h文件 2)Widget.cpp文件

    2024年02月11日
    瀏覽(23)
  • Django學(xué)習(xí)記錄:初步認(rèn)識(shí)django以及實(shí)現(xiàn)了簡(jiǎn)單的網(wǎng)頁(yè)登錄頁(yè)面的前后端開發(fā)

    Django學(xué)習(xí)記錄:初步認(rèn)識(shí)django以及實(shí)現(xiàn)了簡(jiǎn)單的網(wǎng)頁(yè)登錄頁(yè)面的前后端開發(fā)

    1、可以先刪去template文件夾,并在setting里面刪掉這一行 2、在pycharm中創(chuàng)建app: 3、啟動(dòng)app:編寫URL與視圖函數(shù)關(guān)系【urls.py】 ? 編寫視圖函數(shù)【views.py】 ? 啟動(dòng)pycharm項(xiàng)目 4、引用靜態(tài)文件 其中有兩個(gè)文件的導(dǎo)入:(jquery和bootstrap) jquery:https://code.jquery.com/jquery-3.6.0.min.js 可

    2024年02月14日
    瀏覽(25)
  • 用tkinter庫(kù)制作一個(gè)簡(jiǎn)單的登錄注冊(cè)小程序

    用tkinter庫(kù)制作一個(gè)簡(jiǎn)單的登錄注冊(cè)小程序

    目錄 各種組件的布局 制作過(guò)程中的理解 制作過(guò)程中遇到的難點(diǎn) 解決問(wèn)題的方法 tkinter庫(kù)作為python的標(biāo)準(zhǔn)庫(kù)之一,它的功能性十分強(qiáng)大,下面我將使用tkinter庫(kù)制作一個(gè)簡(jiǎn)易的注冊(cè)登錄窗口(很難看就是了)。 一· 制作之前需要大致明白各個(gè)窗體的大致位置,登錄注冊(cè)嘛 自然

    2024年02月09日
    瀏覽(15)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包