servlet中解决内部转发导致的页面css js样式、图片引用消失

路径为相对路径,在转发后以servlet的路径为依据找不到文件,使用绝对路径就是以项目名开头的路径

thymeleaf中使用
th:src="@{/asserts/img/bootstrap-solid.svg}"
以/开头解析后默认添加了项目的项目名
jsp文件使用

<%  
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
request.setAttribute("path", basePath);  
%>  

`src="${path}/asserts/img/bootstrap-solid.svg"

posted @ 2018-08-05 22:12  wei1  阅读(252)  评论(0编辑  收藏  举报