简体   繁体   English

无法将CSS链接到JSP(Spring MVC)

[英]Can't link css to jsp (Spring mvc)

I am struggling with spring mvc file structure. 我正在努力使用Spring MVC文件结构。

I am able to display an image ressource in a jsp but not to link a css to it, even if they are at the same location ! 我能够在jsp中显示图像资源, 但是即使它们位于同一位置,也无法将CSS链接到它!

Here is my file structure : 这是我的文件结构

/src
 /main
   /resources
   /webapps
      /resources
          main.css
          logo.png
      /views
          somePage.jsp
      /WEB-INF
         web.xml
         dispatcher-servlet.xml
         ....  

Here is what I have in my dispatcher : 这是我的调度员中的东西

      <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
     </bean>

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

And in my somePage.jsp : 在我的somePage.jsp中

 <img src="<c:url value="/resources/logo.png" />" alt="blabla" />

 <link href="<c:url value="/resources/main.css" />" rel="stylesheet" />

 ...

The image load correctly but not the css ... 图像加载正确,css不 加载 ...

Note : I have the following message in eclipse : : "invalid location of tag (link). " about the css link... 注意:我在eclipse中有以下消息::“关于CSS链接的标记(链接)的无效位置。”

If you have any idea, thank you by advance ! 如果您有任何想法,请提前谢谢!

Finally it seems to be a cache issue. 最后,这似乎是一个缓存问题。

I just delete my chrome cache and my css appeared. 我只是删除了Chrome缓存,然后出现了CSS。

When I compiled the first time, my css was empty and I filled it later. 当我第一次编译时,我的css是空的,后来我填充了它。 It seems that even after editing it and re-running the project the css state ,wasn't refreshed. 看起来,即使在编辑并重新运行项目后,css状态也没有刷新。

chrome probably kept my css state as empty and didn't detect the update .. weird. chrome可能使我的CSS状态为空,并且没有检测到更新。

You add some code. 您添加一些代码。 like this. 像这样。

Your servelet-context.xml 您的servelet-context.xml

<mvc:default-servlet-handler />

Your jsp 你的jsp

<c:set var="contextPath" value="<%=request.getContextPath()%>"></c:set>


<link href="${contextPath}/resources/main.css" rel="stylesheet" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM