问题描述
一个基于struts1.x的应用,web页面有如下代码<div id="main_r"><iframe name="main" id="centerpage" src="/admin.do?action=include" width="827" height="900" frameborder="0"></iframe></div>即有一个iframe链接到一个action。action的代码如下public ActionForward include(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {return new ActionForward("/admin/main.jsp");}现在有如下问题,当把这个应用部署在tomcat6.x的根目录下,即访问地址是http://localhost/index.jsp的时候毫无问题,action执行了正常的跳转。src链接到了main.jsp但是如果把该应用发布到一个文件夹下http://localhost/test/index.jsp就无法执行了,iframe里嵌入了tomcat反馈的400错误。而且经过我测试,此时的include方法没有得到执行,请问这是怎么回事呢
解决方案
"/"就是web应用的根目录,也就是http://[ip]:[port]/用相对目录(不使用"/"或者"../")或者指定项目名才能得到http://[ip]:[port]/[project_name]/你可以把斜杠去掉试试看,或者<iframe name="main" id="centerpage" src="/admin.do?action=include" width="827" height="900" frameborder="0"></iframe> 前加一个<a href="admin.do?action=include">testPath</a>这样鼠标移上去可以看到链接的地址,从而判断相对路径的层级
解决方案二:
除了楼上说的要改,iframe的src也得改吧
解决方案三:
return new ActionForward("/admin/main.jsp"); 应该跟这个有关系,试试改为 return new ActionForward("admin/main.jsp");