小弟我写了个简单的Login和register但是传到类里就是null,检查了很多遍,不知道问什么传不到action类里,在console里输出name(jsp里)也是null。请大家帮忙看一下哪里出错了。谢谢啦!struts.xml<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>Login.jsp <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>AccountAction.javapublic 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;
}
}
AccountProcessor类是连接DAO的一个类,后台这几个类肯定没有问题,因为我以前用的是servlet,可以运行。关键是Accounts.javapublic class Accounts { private String u_name;
private String pw; public Accounts(String u_name, String pw) {
super();
this.u_name = u_name;
this.pw = pw;
} public Accounts() {
// TODO Auto-generated constructor stub
} public String getU_name() {
return u_name;
} public void setU_name(String u_name) {
this.u_name = u_name;
} public String getPw() {
return pw;
} public void setPw(String pw) {
this.pw = pw;
} @Override
public String toString() {
return "Accounts [u_name=" + u_name + ", pw=" + pw + "]";
}}不好意思,小弟刚来,分数不是很多,还请大家多多关照!感激不尽!Strutsjspjave ee登录
<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>Login.jsp <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>AccountAction.javapublic 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;
}
}
AccountProcessor类是连接DAO的一个类,后台这几个类肯定没有问题,因为我以前用的是servlet,可以运行。关键是Accounts.javapublic class Accounts { private String u_name;
private String pw; public Accounts(String u_name, String pw) {
super();
this.u_name = u_name;
this.pw = pw;
} public Accounts() {
// TODO Auto-generated constructor stub
} public String getU_name() {
return u_name;
} public void setU_name(String u_name) {
this.u_name = u_name;
} public String getPw() {
return pw;
} public void setPw(String pw) {
this.pw = pw;
} @Override
public String toString() {
return "Accounts [u_name=" + u_name + ", pw=" + pw + "]";
}}不好意思,小弟刚来,分数不是很多,还请大家多多关照!感激不尽!Strutsjspjave ee登录
private String password;
接收这两个参数的值 要为他们加上set方法,如果后台处理完成之后要在页面上再显示那就要加上get方法。
AccountAction中name/password的get/set方法呢
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;