配置url rewrite重写url路径之后,在对前台html页面进行渲染的时候,会丢失对css,js等相对目录的应用。
具体解决方法如下:
在<head></head>之间加上<base href=<%=webpath%>/>标签。
比如:
1:urlrewrite.xml
<span style="white-space: pre;"> </span><rule>
<span style="white-space: pre;"> </span><from>/category/([0-9]+)</from>
<span style="white-space: pre;"> </span><to>/article.jsp?act=list&id=$1</to>
<span style="white-space: pre;"> </span></rule>
在访问article.jsp页面的时候如果此页面有相关的css,js,图片等的相对目录的引用,最简单的办法就是在<head>标签之间加上当前网站目录的<base>标签。这样就不会找不到目录了
<%@ include file="taglib.jsp"%>
<%
string path = request.getcontextpath();
string basepath = request.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/";
%>
<html>
<head>
<span style="white-space: pre;"> </span><base href="<%=basepath%>">
</head>
<body>
<span style="white-space: pre;"> <div class="zhongjian1"><img src="images/home/sk.jpg" /></div></span>
</body>
</html>
具体解决方法如下:
在<head></head>之间加上<base href=<%=webpath%>/>标签。
比如:
1:urlrewrite.xml
<span style="white-space: pre;"> </span><rule>
<span style="white-space: pre;"> </span><from>/category/([0-9]+)</from>
<span style="white-space: pre;"> </span><to>/article.jsp?act=list&id=$1</to>
<span style="white-space: pre;"> </span></rule>
在访问article.jsp页面的时候如果此页面有相关的css,js,图片等的相对目录的引用,最简单的办法就是在<head>标签之间加上当前网站目录的<base>标签。这样就不会找不到目录了
<%@ include file="taglib.jsp"%>
<%
string path = request.getcontextpath();
string basepath = request.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/";
%>
<html>
<head>
<span style="white-space: pre;"> </span><base href="<%=basepath%>">
</head>
<body>
<span style="white-space: pre;"> <div class="zhongjian1"><img src="images/home/sk.jpg" /></div></span>
</body>
</html>