首页 新闻 搜索 专区 学院

struts重定向问题,一个奇怪的问题

0
悬赏园豆:10 [已关闭问题] 关闭于 2014-03-26 09:51

<package name="system" namespace="/system" extends="struts-default">
        
<action name="elecUser_*" class="elecUserAction" method="{1}">
    <result name="home">/WEB-INF/page/system/userIndex.jsp</result>
    <result name="add">/WEB-INF/page/system/userAdd.jsp</result>
    <result name="save" type="redirectAction">
        <param name="actionName">elecUser_home</param>
        <param name="namespace">/system</param>
  </result>
</action>
</package>

 

public class ElecUserAction extends BaseAction implements ModelDriven<ElecUserForm>{
    
private IElecUserService elecUserService; private IElecSystemDDlService elecSystemDDlService;
     public IElecSystemDDlService getElecSystemDDlService() {
      return elecSystemDDlService;
     }
    @Resource
    public void setElecSystemDDlService(IElecSystemDDlService elecSystemDDlService) {
        this.elecSystemDDlService = elecSystemDDlService;
    }
    public IElecUserService getElecUserService() {
        return elecUserService;
    }
    @Resource
    public void setElecUserService(IElecUserService elecUserService) {
      this.elecUserService = elecUserService;
    }
     ElecUserForm elecUserForm
= new ElecUserForm();
    @Override
public ElecUserForm getModel() {
        return elecUserForm;
    }
    public String home(){
      List
<ElecUserForm> list = elecUserService.findElecUserList(elecUserForm);
      request.setAttribute(
"list", list);
      return "home";
    }
    public String save(){
        this.elecUserService.save(elecUserForm);
        return "save";
    }
}

     这个表单是添加用户的,点击保存的时候,在一个js函数中验证手机号、email等的数据格式和是否为空等,然后通过document.Form1.action="system/elecUser_save";把表单提交给保存用户的action,在save()方法中进行保存,struts.xml中elecUser_save的result type设成redirectAction,重定向到home,也就是添加完user以后重新跳到显示user的界面。

  奇怪的是,添加的时候结果很不确定,有时候能添加上,有时候不从elecUser_save中走,不知道是什么原因。后来把上面的save方法中的返回值直接改成“home”,配置文件中去掉name=“save”那行,测试时还是有时候保存不了,不经过save()方法的处理

bridge_ca的主页 bridge_ca | 初学一级 | 园豆:194
提问于:2013-12-15 11:57
< >
分享
所有回答(2)
0

关注中

bitbug | 园豆:470 (菜鸟二级) | 2013-12-16 09:57
0

配置文件有问题。result写在action外面了?

angelshelter | 园豆:9676 (大侠五级) | 2013-12-16 17:25

不好意思,粘过来调整格式的时候弄错了,程序里面没写在外面

支持(0) 反对(0) bridge_ca | 园豆:194 (初学一级) | 2013-12-16 18:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册