日期:2014-05-19  浏览次数:20698 次

为啥我访问一个action 会跳转到另一个action里面
Struts2的部分 配置的文件如下: 用spring 注入的


<!-- 组织机构管理:部门管理 -->
  <package name="OrgDep" extends="exception" namespace="/orgDep">
  <!-- 跳转到主页 -->
  <action name="index" class="orgDepAction" method="index">
  <result name="success">/rsgl/org/dep/index.jsp</result>
  </action>
  <!-- 获取树形菜单 -->
  <action name="tree" class="orgDepAction" method="getTree">
  <result name="success">/rsgl/org/dep/index_left.jsp</result>
  </action>
  <!-- 获取列表 -->
<action name="list" class="orgDepAction" method="getList">
<result name="success">/rsgl/org/dep/index_right.jsp</result>
</action>


=====================================

Struts action的 部分代码如下:
// 查询树形菜单
public String getTree(){
try {
List<?> page = this.abstractDao.findList(this.getTreeHql());
System.out.println(page);
} catch (Exception e) {
e.printStackTrace();
}
this.getRequest().setAttribute("page", this.abstractDao.findList(this.getTreeHql()));
return SUCCESS;
}

public String getListHql(){
StringBuilder hql = new StringBuilder();
hql.append("from OrgDep o where 1=1");
return hql.toString();
}
public String getList(){
try {
List<?> page = this.abstractDao.findList(this.getListHql());
System.out.println(page);
} catch (Exception e) {
e.printStackTrace();
}
this.getRequest().setAttribute("page", this.abstractDao.findList(this.getListHql()));
return SUCCESS;
}




我访问 http://..../orgDep/list.action 会执行 getTree() 方法  

而且还执行两次 为啥??????????????



郁闷了一下午了


另外请问一下 Struts 加载 Struts.xml 文件的时候 如何 处理 action 配置信息的






------解决方案--------------------
你确定执行了getTree()方法?
------解决方案--------------------
List<?> page = this.abstractDao.findList(this.getTreeHql());
System.out.println(page);
} catch (Exception e) {
e.printStackTrace();
}
this.getRequest().setAttribute("page", this.abstractDao.findList(this.getTreeHql()));


this.abstractDao.findList(this.getTreeHql()
为什么要调用2次了?这样不就行了this.getRequest().setAttribute("page", page);
------解决方案--------------------
你找找前台有没有两次提交,就像以前ewebeditor就会有这样 的bug,你这代码好像没什么问题,你去前台找找看