用到的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;
    }}