欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

在javaEE中用表格做的登录页面。

程序员文章站 2022-03-27 08:57:46
...

1.没有连接数据库

login.jsp
<body>
    <h2>用户登录页面</h2>
    <form action="" method="post">
        <table border="1">    边框为1
            <tr>
                <td>账号</td>
                <td><input type="text",name="name"/></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password",name="pass"/></td>
            </tr>
            <tr>
                合并
                <td colspan="2"><input type="submit",value="登录"/></td>
            </tr>
        <table>
    </form>
</body>


com.feicui.controller包
public class LoginServlet extends HTTPServlet{

    @Override
    public void dopost(HttpServletRequest request,
                HTTPServletResponse response){
        String name=request.getParameter("name");
        String pass=request.getParameter("pass");
        System.out.println("账号:"+name+",密码:"+pass);
        if("admin".equals(name)&&"123".equals(pass)){
            System.out.println("登录成功!");
            response.sendRedirect("index.jsp");
        }else{
            System.out.println("登录失败!");
            response.sendRedirect("login.jsp");
            
        }
    }
}

web.xml
<servlet>
    <servlet-name>login</servlet-name>
    <servlet-class>LoginServlet的路径</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>/login</url-pattern>
</servlet-mapping>


login.jsp
<body>
    <h2>用户登录页面</h2>
    <form action="" method="post">
        <table border="1">    边框为1
            <tr>
                <td>账号</td>
                <td><input type="text",name="name"/></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password",name="pass"/></td>
            </tr>
            <tr>
                合并
                <td colspan="2"><input type="submit",value="登录"/></td>
            </tr>
        <table>
    </form>
</body>


com.feicui.controller包
public class LoginServlet extends HTTPServlet{

    @Override
    public void dopost(HttpServletRequest request,
                HTTPServletResponse response){
        String name=request.getParameter("name");
        String pass=request.getParameter("pass");
        System.out.println("账号:"+name+",密码:"+pass);
        if("admin".equals(name)&&"123".equals(pass)){
            System.out.println("登录成功!");
            response.sendRedirect("index.jsp");
        }else{
            System.out.println("登录失败!");
            response.sendRedirect("login.jsp");
            
        }
    }
}

web.xml
<servlet>
    <servlet-name>login</servlet-name>
    <servlet-class>LoginServlet的路径</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>/login</url-pattern>
</servlet-mapping>