在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>
上一篇: 使用jQuery和java验证手机号码或者电话号码
下一篇: jquery验证手机号码和邮箱地址例子
推荐阅读