JSP jsessionid appear in CSS and JS link

摘要: In Spring MVC + JSP view page environment.

In Spring MVC + JSP view page environment.

index.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>

In the Spring config file, mapped a resource path,

mvc-dispatcher-servlet.xml
<beans ...
	<context:component-scan base-package="com.mkyong.test" />
	<mvc:resources mapping="/resources/**" location="/resources/" />
</beans>

1. Problem

After deployed, Spring MVC can’t get the CSS and JS resource files, and display resources not found error. Review the generated index.jsp page :

index.jsp
<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>

The jsessionid is appended as a parameter in the CSS and JS url?

2. Solution

To solve this, turn off the page session in JSP page – @page session="true"

index.jsp
<%@page session="true"%>
<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>

OR use ${pageContext.request.contextPath} , instead of this c:url

index.jsp
<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>

References

  1. Stackoverflow : Under what conditions is a JSESSIONID created?
  2. Wikipedia – Session ID

上一篇: Spring Data MongoDB Auto Sequence ID example
下一篇: Java Convert int[] to Integer[] example
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号