创建一个全局使用的application对象
@Component
public class InitComponent {
@Autowired
private ServletContext applicationScope;
// 初始化时执行该方法
@PostConstruct
public void init(){
applicationScope.setAttribute("resUrl", "http://localhost:8123/Search_Link_Res");
}
}
页面中可以直接取值
<c:set var="contextPath" value="${applicationScope.get('resUrl')}"></c:set>
当然使用c标签别忘了在页面引入
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
使用如下:
<link rel="stylesheet" href="${contextPath}/css/bootstrap.min.css">