Le printemps et l'étiquette mvc ressources, ne peut pas atteindre .css, et .fichiers js
Mon utilisation de l'application Printemps 3.0.4(c'est la première version où la balise mvc:ressources fonctionnent bien).
Le problème actuel est que mon application ne peut pas atteindre .css et .js fichiers à partir de la mappé ressources.
Test de la Structure.guerre:
/test -root
|
/static-resource
|
/css
|
/screen.css
|
/js
|
/WEB-INF
|
/index.jsp
Mon test-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/static-resource/"/>
<context:annotation-config/>
<context:component-scan base-package="org.web"/>
<tx:annotation-driven/>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles-defs.xml</value>
</list>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>
<bean id="authenticationInterceptor" class="org.util.AuthenticationInterceptor"/>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages"/>
<property name="defaultEncoding" value="UTF-8"/>
<property name="cacheSeconds" value="-1"/>
</bean>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en"/>
<property name="cookieName" value="bovalta_language"/>
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list>
<ref bean="authenticationInterceptor"/>
<ref bean="localeChangeInterceptor"/>
</list>
</property>
</bean>
</beans>
Dans l'index.jsp j'essaie d'accéder aux ressources sur les deux moyens du printemps url et avec JSTL url comme ci-dessous
<%-- With JSTL url --%>
<link media="screen" href="<c:url value="/resources/css/screen.css"/>" type="text/css"/>
<%-- With Spring url --%>
<spring:url value="/resources" var="resourceUrl"/>
<link media="screen" rel="stylesheet" href="${resourceUrl}/css/screen.css" type="text/css" />
Quand je annuler le déploiement de fichier war dans Tomcat COMME, l'application fonctionne très bien sans aucune exception, mais le serveur Tomcat ne peux pas trouver mon css et js fichiers de ressources.
J'ai essayer de parvenir à un fichier css à travers url http://localhost:8080/test/resources/css/screen.css
mais Tomcat pas trouvé. Toute suggestion sera utile.
Merci d'avance
OriginalL'auteur Vladisav Milosavljevic | 2012-03-29
Vous devez vous connecter pour publier un commentaire.
FYI
Pour tous qui aurait le même problème que j'ai, j'ai résolu mon problème et partagé avec vous:
test-servlet.xml est même, sans modification, comme dans mon post ci-dessus.
dans l'index.page jsp sera:
Principal problème était dans ma web.xml parce que j'ai mappé printemps servlet avec
au lieu de cela, vous devez cartographie seulement
web.xml regardez:
Merci pour tout!
+1 merci beaucoup Vladisav Milosavljevic..
quel est la différence entre / et /*
OriginalL'auteur Vladisav Milosavljevic
J'ai rencontré le même problème et voici comment je l'ai résolu le problème:
Au printemps de fichier de configuration
Remplacer
Et de fournir le chemin d'accès ci-dessous dans la page JSP à la charge statique contenu
Espère que cela va vous aider !
OriginalL'auteur Nilesh