Spring MVC JSPビューページ環境で。

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>

Springの設定ファイルで、リソースパスをマップし、

mvc-dispatcher-servlet.xml

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

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

1.問題

デプロイ後、Spring MVCはCSSおよびJSリソースファイルを取得することができず、エラーが見つからないリソースを表示します。生成された `index.jsp`ページを見直してください:

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>

`jsessionid`はCSSとJS urlのパラメータとして追加されますか?

2.解決策

これを解決するには、JSPページのページセッションをオフにします。 –

@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>

または、この

c:url`の代わりに

$ {pageContext.request.contextPath} `を使用してください。

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>