jsp和struct2的路径问题

来源:互联网 发布:sql 参数 编辑:程序博客网 时间:2024/06/05 06:23

在jsp中,用如下代码

<a href="/index.jsp">index</a>

则该链接是指向webapps下的index.jsp。


<a href="index.jsp">index</a>

则该链接是指向该项目目录下的index.jsp。

在struct2中,若用

<a href="index.jsp">index</a>,

则该链接是指向的是该页面地址下的index.jsp。

如,该页面的地址是http://localhost:8080/structs001/path,

该链接是指向的是http://localhost:8080/structs001/path/hello.jsp。

为避免出现这种问题,可用绝对路径

String path=request.getContextPath();
 String basePath=request.getScheme()+"://"+request.getServerName()+":"
        +request.getServerPort()+path+"/";

<base href="<%=basePath%>">。

0 0