there are all kinds of ways to deal with it, and I don't seem to think which one is more general.
there is a very important problem: before your page is visited, the path is uncertain ! And according to the sevlet specification, this path is under session. That is to say, each visit may be different, so any method of writing death will make the project rigid and lose some of the flexibility of the definition.
< H1 > spring tags, for jsp < / H1 >
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:url value="/css/main.css" var="springCss" />
< H1 > < c:url/ > for jsp < / H1 >
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:url value="/css/main.css" var="jstlCss" />
<link href="${jstlCss}" rel="stylesheet" />
< H1 > webjars sevlet method, which can be used on jsp and html static pages < / H1 >
the idea is to package static pages and access them through a specific url prefix, which is handled by the interceptor or sevlet
maven pom.xml configuration:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
Page template:
<link rel="stylesheet" type="text/css" href="webjars/bootstrap/3.3.7/css/bootstrap.min.css" />
< H1 > html base tagging method < / H1 >
< H2 > jsp, ftl & etc. < / H2 >
if you want to separate movement and movement, you need to define several different variables and inject them from the backend
.
<!-- base sitemesh , -->
<base href="${host}/${context}/${language}/">
...<!-- -->
<link rel="stylesheet" href="css/style.css" />
<script src="js/script.js"></script>
...
<a href="home">home</a>
<a href="faq">faq</a>
<a href="contact">contact</a>
...
<img src="img/logo.png" />
< H2 > html static, write dead directly, or also relative path < / H2 >
<base href="http://example.com/en/" />
<!-- IE -->
<!-- -->
<base href="//example.com/somefolder/">
<!-- -->
<base href="/somefolder/">
it is not good to write dead at present, but if it is only in a few places, it is reluctantly acceptable
.