你的位置:首页 > Java教程

[Java教程]servlet的登陆案例


Users.java

 1 package com.po; 2  3 public class Users { 4   private String username; 5   private String password; 6    7   public Users(){}; 8    9   public String getUsername() {10     return username;11   }12   public void setUsername(String username) {13     this.username = username;14   }15   public String getPassword() {16     return password;17   }18   public void setPassword(String password) {19     this.password = password;20   }21   22   23 }

 

新建GoLogin.java和LoginServlet.java的servlet类

分别修改他们的doGet和doPost方法

 

 

 

 

login.jsp:

1 <form action="servlet/LoginServlet" method="post">2     <table>3       <tr><td>用户名:</td><td><input type="text" name="username" /></td></tr>4       <tr><td>密码:</td><td><input type="password" name="password" /></td></tr>5       <tr><td></td><td><input type="submit" value="登陆" /></td></tr>6     </table>7   </form>

loginFailed.jsp

1 <h1>登陆失败</h1>2 <a href="servlet/GoLogin" >返回登陆界面</a>