日期:2014-05-18  浏览次数:20659 次

调用struts的action路径问题。
问题描述:我使用的是DispatchBaseAction,这样就可以在一个页面中使用多个提交了。
但是这样就出现了问题。我把所有页面放入到一个叫pages的文件夹中。这样打开初始的url为
http://localhost:8088/KP/pages/workresult_examination.jsp
点击一个提交页面的url变成
http://localhost:8088/KP/chengguo.do?method=find
可以看到页面的路径变化了。

我使用js来实现参数赋值的如下
JScript code

function goto(a,b){
      var frm=document.forms[0];
      var ac = "../chengguo.do?method="+a+"&bh="+b; 
      frm.action=ac;
      frm.submit(); 
       
    }



这就出现问题了,我再在当前页面中点提交按钮的时候路径就变成了
http://localhost:8088/chengguo.do?method=find

结果自然就找不到了。有什么办法解决,比如用绝对路径一类的


大家帮帮忙。。 郁闷死

------解决方案--------------------
用var ac = "<%=request.getContextPath()%>/chengguo.do?method="+a+"&bh="+b;
------解决方案--------------------
LS正解
------解决方案--------------------
String contextPath = request.getContextPath();
先获取一下绝对路径。
这一句 var ac = "../chengguo.do?method="+a+"&bh="+b; 
改成下面的试试
 var ac = "<%= contextPath %>/chengguo.do?method="+a+"&bh="+b;
------解决方案--------------------
Java code
frm.action = "<html:write href = 'xxx.do'>"
frm.action = "<html:write page = 'xxx.do'>"