首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

struts1求解!为啥action中传递的actionform是空

2012-07-29 
struts1求解!为什么action中传递的actionform是空这是登录页面的部分代码HTML codeform nameusersForm

struts1求解!为什么action中传递的actionform是空
这是登录页面的部分代码

HTML code
    <form name="usersForm" method="post" action="logon.do?action=logon">    <table width="432" height="236" border="0" cellpadding="0" cellspacing="0" background="images/login.gif">        <tr align="center">          <td height="128" colspan="2" >&nbsp;</td>        </tr>                <tr>          <td width="170" height="31" align="center" >用户名:</td>          <td width="230" height="31" >            <input name="username" type="text" class="input">        </td>        </tr>        <tr>          <td width="170" height="29" align="center">密&nbsp;&nbsp;码:</td>          <td width="230" height="29" ><input name="password" type="password" class="input" ></td>        </tr>        <tr>          <td height="70" colspan="2" align="center" ><input type="submit" name="Submit" value="登陆" class="button">          &nbsp;            <input type="reset" name="Submit2" value="重置"class="button"></td>          </tr>            </table>

这是struts-config.xml
XML code
<struts-config>  <form-beans>      <form-bean name="userForm" type="com.ems.actionform.UsersForm" />  </form-beans>  <global-forwards>    <forward name="error" path="/error.jsp" />  </global-forwards>    <action-mappings>    <action path="/logon" type="com.ems.action.UsersAction" name="userForm" scope="request">      <forward name="success" path="/manage.jsp" />      <forward name="failed" path="/failed.jsp" />    </action>  </action-mappings></struts-config>

这是UserForm
Java code
package com.ems.actionForm;import javax.servlet.http.HttpServletRequest;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionMapping;import com.ems.model.Users;import com.ems.util.DateUtil;public class UsersForm extends ActionForm {       private Long id;    private String username;    private String password;    private Byte sex;    private String birthday;    private String createtime;    private Byte isadmin;    private String content;            public Long getId() {        return id;    }    public void setId(Long id) {        this.id = id;    }    public String getUsername() {        return username;    }    public void setUsername(String username) {        this.username = username;    }    public String getPassword() {        return password;    }    public void setPassword(String password) {        this.password = password;    }    public Byte getSex() {        return sex;    }    public void setSex(Byte sex) {        this.sex = sex;    }    public String getBirthday() {        return birthday;    }    public void setBirthday(String birthday) {        this.birthday = birthday;    }    public String getCreatetime() {        return createtime;    }    public void setCreatetime(String createtime) {        this.createtime = createtime;    }    public Byte getIsadmin() {        return isadmin;    }    public void setIsadmin(Byte isadmin) {        this.isadmin = isadmin;    }    public String getContent() {        return content;    }    public void setContent(String content) {        this.content = content;    }    public void reset(ActionMapping arg0, HttpServletRequest arg1) {        this.id=null;        this.username=null;        this.password=null;        this.isadmin=null;        this.createtime=null;        this.content=null;        this.sex=null;        this.birthday=null;            }    public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {        return null;    }        public String toString() {        StringBuffer toStr = new StringBuffer();        toStr.append("[UsersForm] = [\n");        toStr.append("    id = " + this.id + ";\n");        toStr.append("    username = " + this.username + ";\n");        toStr.append("    password = " + this.password + ";\n");        toStr.append("    sex = " + this.sex + ";\n");        toStr.append("    birthday = " + this.birthday+ ";\n");        toStr.append("    createtime = " + this.createtime+ ";\n");        toStr.append("    isadmin = " + this.isadmin+ ";\n");        toStr.append("    content = " + this.content + ";\n");        toStr.append("    ];\n");        return toStr.toString();    }        public Users populate(){        Users u=new Users();        u.setId(getId());        u.setIsadmin(getIsadmin());        u.setContent(getContent());        u.setUsername(getUsername());        u.setPassword(getPassword());        u.setSex(getSex());        u.setBirthday(DateUtil.parseToDate(getBirthday(),DateUtil.yyyyMMdd));        u.setCreatetime(DateUtil.parseToDate(getCreatetime(),DateUtil.yyyyMMddHHmmss));        return u;    }} 


这是UserAction.java
Java code
package com.ems.action;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.hibernate.HibernateException;import com.ems.actionForm.UsersForm;import com.ems.model.Users;import com.ems.service.UsersDao;public class UsersAction extends Action {    private UsersDao usersDao = new UsersDao();    public ActionForward execute(ActionMapping mapping, ActionForm form,            HttpServletRequest request, HttpServletResponse response) throws Exception {        String action =request.getParameter("action");        System.out.println("action = "+action+",这里是测试2");        System.out.println("\nUsersAction*********************action="+action);        if(action==null||"".equals(action)){            return mapping.findForward("error");        }else if("listuser".equals(action)){            return listUser(mapping,form,request,response);        }else if("adduser".equals(action)){            return addUsers(mapping,form,request,response);        }else if("logon".equals(action)){            System.out.println("这里是测试3");            return logon(mapping,form,request,response);        }else if("updateuser".equals(action)){            return updateUser(mapping,form,request,response);        }else if("deleteuser".equals(action)){            return deleteUser(mapping,form,request,response);        }else if("selectuser".equals(action)){            return selectUser(mapping,form,request,response);        }        return mapping.findForward("error");    }    private ActionForward logon(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws HibernateException {        System.out.println(request.getParameter("password")+"这里是测试4");        System.out.println("form = "+form+"这里是测试5");        UsersForm usersform=(UsersForm)form;        System.out.println("userform.getUsername() = "+usersform.getUsername()+"这里是测试6");        System.out.println("userform.getPassword() = "+usersform.getPassword()+"这里是测试7");        Users users=new Users();        users.setUsername(usersform.getUsername());        users.setPassword(usersform.getPassword());        boolean flag=usersDao.logonUsers(users);        if(flag){            request.getSession().setAttribute("users",users);            return mapping.findForward("success");        }else{            return mapping.findForward("failed");       }    }}



[解决办法]
<form name="userForm"> 而不是usersForm
[解决办法]
<form name="userForm"> 而不是usersForm!!!!!!
都给你解释了~~~
后台是什么form,<form>标签name属性就是什么
[解决办法]

热点排行
Bad Request.