spring boot学习-页面访问
在访问之前,将页面内容添加到项目中来,直接运行看下效果:
与在webstorm上显示有所区别。
需要在jsp页面中写Java代码,让Java来获取项目的根路径,通过绝对路径的方式引入这些图片文件。在jsp文件的开头写入下面的代码:
<%
String path = request.getContextPath();
String basePath=null;
basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
int port=request.getServerPort();
if(port==80){
basePath=request.getScheme()+"://"+request.getServerName()+path;
}else{
basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
}
request.setAttribute("basePath", basePath);
%>
代码只是获取基本的路径,而request就是JSP隐式对象,JSP就是Servlet,request.setAttribute(“basePath”, basePath) 表示将得到的basePath(项目根路径)存放到request作用域中,需要在图片路径前面加入这行代码$。如下:
<div class="glyphicon-ban-circle" style="height:100%;background-image:url('${basePath}asserts/img/2.jpg')">