用到的formbean/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yourcompany.struts.form;import java.util.ArrayList;import javax.servlet.http.HttpServletRequest;import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;import com.user.model.User;/** 
 * MyEclipse Struts
 * Creation date: 06-19-2007
 * 
 * XDoclet definition:
 * @struts.form name="userForm"
 */
public class UserForm extends ActionForm {
private static final long serialVersionUID=1L;
/** newEmail property */
private String newEmail; /** newUsername property */
private String newUsername; /** newDescription property */
private String newDescription; /** newPassword property */
private String newPassword; /** newTel property */
private String newTel; /** newName property */
private String newName; /** newRole property */
private String newRole;

private ArrayList userList;
private String hid;
private User viewUser;
private User updateUser;
/*
 * Generated Methods
 */ /** 
 * Method reset
 * @param mapping
 * @param request
 */
/** 
 * Returns the newEmail.
 * @return String
 */
public String getNewEmail() {
return newEmail;
} /** 
 * Set the newEmail.
 * @param newEmail The newEmail to set
 */
public void setNewEmail(String newEmail) {
this.newEmail = newEmail;
} /** 
 * Returns the newUsername.
 * @return String
 */
public String getNewUsername() {
return newUsername;
} /** 
 * Set the newUsername.
 * @param newUsername The newUsername to set
 */
public void setNewUsername(String newUsername) {
this.newUsername = newUsername;
} /** 
 * Returns the newDescription.
 * @return String
 */
public String getNewDescription() {
return newDescription;
} /** 
 * Set the newDescription.
 * @param newDescription The newDescription to set
 */
public void setNewDescription(String newDescription) {
this.newDescription = newDescription;
} /** 
 * Returns the newPassword.
 * @return String
 */
public String getNewPassword() {
return newPassword;
} /** 
 * Set the newPassword.
 * @param newPassword The newPassword to set
 */
public void setNewPassword(String newPassword) {
this.newPassword = newPassword;
} /** 
 * Returns the newTel.
 * @return String
 */
public String getNewTel() {
return newTel;
} /** 
 * Set the newTel.
 * @param newTel The newTel to set
 */
public void setNewTel(String newTel) {
this.newTel = newTel;
} /** 
 * Returns the newName.
 * @return String
 */
public String getNewName() {
return newName;
} /** 
 * Set the newName.
 * @param newName The newName to set
 */
public void setNewName(String newName) {
this.newName = newName;
} /** 
 * Returns the newRole.
 * @return String
 */
public String getNewRole() {
return newRole;
} /** 
 * Set the newRole.
 * @param newRole The newRole to set
 */
public void setNewRole(String newRole) {
this.newRole = newRole;
} public String getHid() {
return hid;
} public void setHid(String hid) {
this.hid = hid;
} public User getUpdateUser() {
return updateUser;
} public void setUpdateUser(User updateUser) {
this.updateUser = updateUser;
} public ArrayList getUserList() {
return userList;
} public void setUserList(ArrayList userList) {
this.userList = userList;
} public User getViewUser() {
return viewUser;
} public void setViewUser(User viewUser) {
this.viewUser = viewUser;
}
}

解决方案 »

  1.   

    在点保存时action作出的反应是
    UserForm userForm=(UserForm)form;
    User updateUser=userForm.getUpdateUser();
    String username=updateUser.getUsername();
    Session session=HibernateSessionFactory.getSession();
    Transaction tx=session.beginTransaction();
    String sql="select u from User u where u.username='"+username+"'";
    Query q=session.createQuery(sql);
    ArrayList userList=(ArrayList)q.list();
    User user=(User)userList.get(0);
    user=updateUser;
    session.save(user);
    tx.commit();
    session.close();
      

  2.   

    用到的javabean
    package com.user.model;public class User {
    private int id;
    private String username;
    private String password;
    private String role;
    private String name;
    private String tel;
    private String email;
    private String description;

    public String getDescription() {
    return description;
    }
    public void setDescription(String description) {
    this.description = description;
    }
    public String getEmail() {
    return email;
    }
    public void setEmail(String email) {
    this.email = email;
    }
    public int getId() {
    return id;
    }
    public void setId(int id) {
    this.id = id;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    public String getPassword() {
    return password;
    }
    public void setPassword(String password) {
    this.password = password;
    }
    public String getRole() {
    return role;
    }
    public void setRole(String role) {
    this.role = role;
    }
    public String getTel() {
    return tel;
    }
    public void setTel(String tel) {
    this.tel = tel;
    }
    public String getUsername() {
    return username;
    }
    public void setUsername(String username) {
    this.username = username;
    }

    }
      

  3.   

    servlet和这个javabean绑定了吗?报的错是没有指定的bean!
      

  4.   

    应是绑定的。
    <action-mappings >
        <action
          attribute="userForm"
          name="userForm"
          path="/manageuser"
          scope="request"
          type="com.yourcompany.struts.action.ManageUserAction"
          validate="false" >
          <forward name="update_user" path="/update_user.jsp" />
          <forward name="new_user" path="/new_user.jsp" />
          <forward name="view_user" path="/view_user.jsp" />
          <forward name="main_user" path="/main_user.jsp" />
         </action>  </action-mappings>
      

  5.   

    我的保存的bean应是formbean中的属性类User.
    不知道为什么这样会不行。求救啊
      

  6.   

    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)dopost方法这里有问题,看一看servlet里面是不对应,或把jsp改成get方法,试一下
      

  7.   

    form的配置有有没有问题,报错是form的问题,在action里面设一个断点肯定到不了,form-bean的配置文件呢?
      

  8.   

    这个是struts-config文件的内容
    <struts-config>
      <data-sources />
      <form-beans >
        <form-bean name="userForm" type="com.yourcompany.struts.form.UserForm" />  </form-beans>  <global-exceptions />
      <global-forwards />
      <action-mappings >
        <action
          
          name="userForm"
          path="/manageuser"
          scope="request"
          type="com.yourcompany.struts.action.ManageUserAction"
          validate="false" >
          <forward name="update_user" path="/update_user.jsp" />
          <forward name="new_user" path="/new_user.jsp" />
          <forward name="view_user" path="/view_user.jsp" />
          <forward name="main_user" path="/main_user.jsp" />
         </action>  </action-mappings>  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
    </struts-config>
      

  9.   

    html:text name="userForm"  property="updateUser.password" >
    中的name是text的名字,自己取个
    property改为property="password"其它的都照着这个改下
      

  10.   

    我试了一下还是不行。name应是javabean。默认是userForm(我的程序中)
    property是text名字。所以才设置为updateUser.xxxx
    updateUser是userForm(ActionForm)中的属性User类
      

  11.   


    有点想法。
    我的FormBean是userForm
    里面有一个属性User updataUser;
    我感觉报错就是因为它没有办法保存
    因为我把userForm的scope设置为session.它就不会报上面的错误
      

  12.   

    我把FormBean中的User updateUser改成User updateUsery=new User().虽然不报错了。
    但是保存的时候updateUser只是一个空对象。没有把网页中修改的值传到这个User类中。
      

  13.   

    public class UserForm extends ActionForm {
       User updateUser=new User();
       public void setUpdateUser(User user){
            this.updateUser=user;
       }
       public User getUpdateUser(){
            return updateUser;
       }
    }ActionForm中User updateUsery=new User().以后,把它当作ActionForm的一个属性,也要set和get方法的
      

  14.   

    先说一下你的代码有个问题了.
    一你用了ActionForm还用什么javaBean?
    二标签里的name是对应的表单所连接的action所对应的form所以可以不用写
    三标签里只写property属性就行了是form里的元素
    4你想这样的获取整个类.有必要吗?
      

  15.   

    楼主是在ActionForm中调用了new了另一个JavaBean,将表单属性存储到new出的javaBean中,
    所以他这样写updateUser.xxxx,这样做也是可以的,只是他的代码中有些问题
      

  16.   

    谢谢大家的指教。
    我有一个user的javabean是因为要用hibernate和数据库打交道。
    formBean还有一些额外属性
    是为了方便在request保存一些需要用的user.比如说增加一个新,
    更新一个。察看一个。
    能指教一下具体什么问题吗。
    我QQ123501875。希望得到大家的帮助。