我有一个jsp页面a.jsp,放在bg文件夹里,a.jsp里面有一个链接<a href="../b.jsp">我是链接</a>,
在struts2中配置result的时候出了问题,配置成
<action name="myAction" class="xxx" method="xxx">
<result>bg/a.jsp</result>
</action>
这样的时候,
用http://localhost:8080/myapp/myAction.do来访问,在a中的连接的路径就出错了,
原意是退出到bg外面的目录,即http://localhost:8080/myapp/b.jsp,
现在变成链接到http://localhost:8080/b.jsp了,请问这是什么问题,怎么解决呢?

解决方案 »

  1.   

    那就取下路径就好了
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><a href="<%=basePath %>b.jsp">
      

  2.   

    <a href="../b.jsp">我是链接 </a>, 
    凡是这种连接,都最好带上上下文路径,比如
    <a href="<%=request.getContextPath()%>/b.jsp">我是链接 </a>
      

  3.   

    最好别出现绝对路径,代码不好移动修改.
    实在要写的也在配置文件property或者xml等全局配置里面
      

  4.   

    6楼 得分:0
    引用 1 楼 sangshusen_1988 的回复:
    最好写成绝对路径最好别出现绝对路径,代码不好移动修改.
    实在要写的也在配置文件property或者xml等全局配置里面
      

  5.   

    <a href="<%=path>/b.jsp">我是链接</a>
    这个就够用了