Resource path in ssm framework

Add the following configuration to the Spring file

<mvn:annotation-driven/>
	<mvn:default-servlet-handler/>


File Directory


Relative paths can be used in index.jsp, for example

<link rel="stylesheet" href="static/css/bootstrap.min.css">
<script type="text/javascript" src="static/js/jquery-1.11.1.min.js"></script>

Absolute path can be used in situation.jsp (if it is the same as above, the resource will not be found, because the jsp is in the web directory), for example

<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/situation.css">
<img src="${pageContext.request.contextPath}/static/images/8.png"/>

--------------------------------------------------------------------------------

You can also add the following code at the beginning of the jsp file:

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

Then write this when referencing the resource:

<link rel="stylesheet"  
    href="<%=basePath%>static/lib/font-awesome/css/font-awesome.css">  


If you want to refer to images in images in CSS styles, you can only use relative paths. (".." means jump to the parent directory), for example

background: url(../images/3.png) transparent no-repeat ;


The first time I encountered this problem, it took a day to solve it, and finally I found the boss to know that it can still be like this.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325811572&siteId=291194637