JavaWeb商城项目(Day05)Web层(登录页面的html+Servlet程序)

   日期:2020-11-16     浏览:120    评论:0    
核心提示:登录的Servlet程序public class LoginServlet extends HttpServlet { private UserService userService = new UserServiceImpl(); @Override protected void doPost(HttpServletRequest req, HttpServletRes

登录的Servlet程序


public class LoginServlet extends HttpServlet { 
    private UserService userService = new UserServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 
        
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        User loginUser = userService.login(new User(null, username, password, null));
        if (loginUser != null) { 
            req.getRequestDispatcher("pages/user/login_success.html").forward(req,resp);
        }else { 
            req.getRequestDispatcher("pages/user/login.html").forward(req,resp);
            // 在页面提示用户名或密码有误
            
        }
    }
}

当完成基本功能之后,如果我登录不成功,跳转到当前的页面后想让服务器回传数据提示用户,用到JSP技术。

登录页面 login.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <link rel="stylesheet" href="../../static/css/style.css">
    <script></script>
</head>
<body>
    <div id="login_header">
<!-- <img class="logo_img" alt="无法显示" src="" alt="">-->
    </div>

    <div class="login_banner">
        <div id="l_content">
            <span>欢迎登录</span>
        </div>
        <div id="content">
            <div class="login_form">
                <div class="login_box">
                    <div class="tit">
                        <h1>卡宾会员</h1>
                        <a href="regist.html">立即注册</a>
                    </div>

                    <div class="msg_cont">
                        <b></b>
                        <span class="errorMsg">请输入用户名和密码</span>
                    </div>
                    <div class="form">
                        <form action="http://localhost:8080/loginServlet" method="post">
                            <label>用户名称:</label>
                            <input type="text" name="username" class="itxt">
                            <br>
                            <br>
                            <label>用户密码:</label>
                            <input type="password" name="password" class="itxt">
                            <br>
                            <br>
                            <input id="sub_btn" type="submit" value="登录">
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="bottom">
        <span>
            程序彤卡宾商城.Copyright &copy;2020.11.12
        </span>
    </div>
</body>
</html>

登录成功跳转页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册成功页面</title>
    <link rel="stylesheet" href="../../static/css/style.css">
</head>
<body>
    <div class="bottom">

    </div>
    <div id="main">
        <h1>登录成功!<a href="">跳转到?</a></h1>
    </div>

    <div id="bottom">
        <span>卡宾商城.Copyright &copy;2020.11.12</span>
    </div>
</body>
</html>
 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服