qusthuang
qusthuang
2012-05-23 13:11
浏览 190
已采纳

关于struts2 redirectAction的问题

我在页面上提交表单,经过saveUser action后跳转到findUsers action,为设么findUsers action中user还是saveUser action中的值(页面模型)?????????



////////////////////////////////////////////////////////

/system/user.jsp



findUsers

findUsers

/////////////////////////////////////////////////

public class UserAction extends BaseAction{

private String id;

[color=red]private EasyUser[color=red] user;//页面模型[/color]

private List<EasyUser> list;//返回所有用户

private List<EasyJuese> jueseList;//所有角色

private List<EasyBumen> bumenList; //所有部门

private String role;        //页面查询条件
private String department;  //页面查询条件



public String getRole() {
    return role;
}

public void setRole(String role) {
    this.role = role;
}

public String getDepartment() {
    return department;
}

public void setDepartment(String department) {
    this.department = department;
}

public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

public EasyUser getUser() {
    return user;
}

public void setUser(EasyUser user) {
    this.user = user;
}

public List<EasyUser> getList() {
    return list;
}

public void setList(List<EasyUser> list) {
    this.list = list;
}




public List<EasyJuese> getJueseList() {
    return jueseList;
}

public void setJueseList(List<EasyJuese> jueseList) {
    this.jueseList = jueseList;
}

public List<EasyBumen> getBumenList() {
    return bumenList;
}

public void setBumenList(List<EasyBumen> bumenList) {
    this.bumenList = bumenList;
}
/**
 * 显示用户列表
 * 方法名:findUsers
 * 描述:

 * @param @return
 * @return String
 */
public String findUsers(){
    user=null;
    role="-1";
    department="-1";
    jueseList=getEasyJueseService().findAll();
    bumenList=getEasyBumenService().findAll();
    list=getEasyUserService().findAll();

    return SUCCESS;
}

public String deleteUser()throws BzException{
    try {
        id=new String(id.getBytes("iso-8859-1"),"utf-8");
    } catch (Exception e) {
        throw new BzException("id异常");
    }

    try {
        if(!getEasyUserService().delete(getEasyUserService().findByUserId(id)))
            throw new BzException("删除用户不存在") ;
    } catch (Exception e) {
            throw new BzException("删除异常");
    }

    return SUCCESS;
}


/**
 * 
 * 方法名:saveUser
 * 描述:保存用户


 * @param @return
 * @return String
 * @throws BzException 
 */
public String saveUser() throws BzException{
    int rid=Integer.parseInt(role);
    int did=Integer.parseInt(department);
    try {
        EasyJuese role=getEasyJueseService().findJueseById(rid);
        EasyBumen dept=getEasyBumenService().findBuMenById(did);
        user.setEasyJuese(role);
        user.setEasyBumen(dept);
        [color=red]getEasyUserService().save(user)[/color];
    } catch (Exception e) {
        throw new BzException("添加用户出错,系统中已存在用户"+user.getUserid());
    }


    return SUCCESS;
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • renxin111
    renxin111 2012-05-24 15:49
    已采纳

    问下你的Action是"单例"的还是"原型"的,
    如果是"单例"的话,你在saveUser的时候user是有值的,
    转到findUsers的时候,
    值还是saveUser时候的值,

    点赞 评论
  • wanghuanqiufly
    wanghuanqiufly 2012-05-23 15:54

    事务提交了吗

    点赞 评论

相关推荐