日期:2014-05-16  浏览次数:20580 次

spring mvc下css js中的jsession id?
在http://www.mkyong.com/spring-mvc/jsp-jsessionid-added-to-css-and-js-link/中

提到了在spring mvc+jsp中,对资源文件的引入问题,比如:

<html>
  <head>
  <title>Welcome!</title>
 
  <c:url var="assets" value="/resources/abc" />
  <link href="${assets}/css/style.min.css" rel="stylesheet">
 
  <script src="<c:url value="/resources/js/jquery.1.10.2.min.js" />">
  </script>
 
  </head>
  ...
</html>


  <beans ...
<context:component-scan base-package="com.mkyong.test" />

<mvc:resources mapping="/resources/**" location="/resources/" />
</beans>

  但出现:

  <html>
  <head>
  <title>Welcome!</title>

  <link href="/resources/simpliq;jsessionid=2957A...5C8DA/css/style.min.css"
    rel="stylesheet">

  <script src="/resources/js/jquery.1.10.2.min.js;jsessionid=2957A...5C8DA">
  </script>
  </head>
  ...
</html>

  就是带了jsession id,解决方法有两个
1)
   <%@page session="true"%>

2)
使用:${pageContext.request.contextPath}
  <html>
  <head>
  <title>Welcome!</title>

  <link href="${pageContext.request.contextPath}/resources/css/style.min.css"
    rel="stylesheet">

  <script src="${pageContext.request.contextPath}/resources/js/jquery.1.10.2.min.js" />">
  </script>

  </head>
  ...
</html>