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

关于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 2012-05-24 15:49
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)