日期:2014-05-18 浏览次数:20641 次
<action name="login" class="com.estore.action.AccountAction" method = "checkLogin">
<result name="success">/MainPage.jsp</result>
<result name="wrongPassword">/loginFailure.jsp
<result name="noAccount">/loginFailure.jsp</result>
<result name="unknownLoginError">/loginFailure.jsp</result></result>
</action>
<s:form action="login">
<s:textfield name="name" key="User Name" />
<s:password name="password" key="Password" />
<s:submit value="Login" align="left"/>
</s:form>
public class AccountAction extends ActionSupport implements SessionAware {
private final static String SUCCESS = "success";
private final static String WRONGPASSWORD = "wrongPassword";
private String name;
private String password;
private Accounts account= new Accounts();;
public String checkLogin() {
// DynaValidatorForm = (DynaValidatorForm) form;
System.out.println(name); //此处输出结果是null
account.setU_name(name);
account.setPw(password);
AccountProcessor ap = new AccountProcessor();
try {
if ((ap.validateAcc(account)) == 1) {
return SUCCESS;
} else if ((ap.validateAcc(account)) == 0) {
return WRONGPASSWORD;
} else if ((ap.validateAcc(account)) == 2) {
return NOACCOUNT;
} else if ((ap.validateAcc(account)) == 3) {
return UNKNOWLOGINERROR;
}
} catch (ParseException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return UNKNOWLOGINERROR;
}
}
public class Accounts {
private String u_name;