日期:2014-05-19 浏览次数:20707 次
//Login.jsp <s:form action="Login.action" theme="simple" namespace="/"> <table border="0" style="width: 600px;" cellpadding="5"> <tr> <th colspan="2" width="400px"> <h1><label>Login System</label></h1> </th> <td width="200px"> </td> </tr> <tr> <td> <label style="font-size: large;">User ID:</label> </td> <td> <s:textfield name="userid" cssStyle="font-size: large; width: 230px"></s:textfield> </td> <td rowspan="3"> </td> </tr> <tr> <td> <label style="font-size: large;">Password:</label> </td> <td> <s:password name="password" cssStyle="font-size: large; width: 230px"></s:password> </td> </tr> <tr> <td colspan="2" align="right"> <s:submit value="提交" cssStyle="font-size: large;"></s:submit> </td> </table> </s:form> //用form提交 struts.xml <action name="Login" Class="ActionForm.LoginAction"> <result name="success">/index.jsp</result> <result name="input">/Login.jsp</result> </action> //LoginAction.java private int userid; private int password; private Connection conn = null; private Statement sm = null; private ResultSet rs = null; public int getUserid() { return userid; } public void setUserid(int userid) { this.userid = userid; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String execute() throws Exception { int i = login(userid, password); if(i >0) { return SUCCESS; } else { return INPUT; } } public int login(int userid,String password) throws SQLException { int i = 0; StringBuffer sb = new StringBuffer(); sb.append("select uname from login_user_Table where uid='").append(userid).append("' and upassword='").append(password).append("'"); System.out.println(sb.toString()); try { DBConnection db = new DBConnection(); conn = db.getConnection(); sm = conn.createStatement(); rs = sm.executeQuery(sb.toString()); if(rs.next()) { i = 1; } else { i=0; } } catch (Exception e) { e.printStackTrace(); } return i; }