Question : SpringMVC跳转时,跳转页面图片无法正确加载
@Controller
@RequestMapping("/user")
public class UserController {
@RequestMapping("/testException")
public String testException() throws SysException {
System.out.println ("testException·······");
try {
//自定义异常
int i =1/0;
} catch (Exception e) {
e.printStackTrace ();
throw new SysException ("查询用户时出错!");
}
return "success";
}
}
Solution : 在写连接路径的时候建议用 ${pageContext.request.contextPath} 在字符串开头
<div class="centers" style="margin-top: 80px">
<img src=" <%=request.getContextPath() %>/img/error.png">
</div>
还有可能是在springmvc配置文件中,没有配置静态资源不拦截
<mvc:resources mapping="/img/**" location="/img/"></mvc:resources>
<!-- css js 文件同理 -->
<!--<mvc:resources mapping="/js/**" location="/js/"></mvc:resources>-->
<!--<mvc:resources mapping="/css/**" location="/css/"></mvc:resources>-->