小弟我写了个简单的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登录

解决方案 »

  1.   

    private String name;
    private String password;
    接收这两个参数的值 要为他们加上set方法,如果后台处理完成之后要在页面上再显示那就要加上get方法。
      

  2.   

    你那个jsp中,form中怎么没有method传输方式呢
      

  3.   


    AccountAction中name/password的get/set方法呢
      

  4.   

    AccountAction.java这action中的name,password属性都要get,set,在下面的引用中System.out.println(name);    //此处输出结果是null ,这里才会获得的

    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;
      

  5.   

    哈哈,谢谢大家啊,刚刚学习struts,还不是弄的很明白。感谢各位,分数实在是太少不好意思,就给第一个回复的和回复最多的人好了