2013-04-15 57 views
0

我有一個Web應用程序,我正在使用Spring,Sitemesh,JPA和Shiro編寫基礎。這實際上是我第一次使用這些框架,因爲我很久以來一直在使用Struts/ibatis。Spring MVC資源(.js,.css,.png)在瀏覽器完成加載之前「中止」

我得到的問題很奇怪,我已經做了幾天的研究和試驗和錯誤,什麼都沒發現。我在資源加載中止的瀏覽器中刷新頁面時出現間歇性問題。他們似乎有時會部分加載,有時甚至完全缺失。

設置的服務器是tomcat/apache。

我在服務器端查看過,沒有任何錯誤可以看到。

這裏是代碼從我的web.xml和我的基本servlet.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 

<display-name>myapp</display-name> 
<description>myapp</description> 

<listener> 
    <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class> 
</listener> 

<filter> 
    <filter-name>ShiroFilter</filter-name> 
    <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>ShiroFilter</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>INCLUDE</dispatcher> 
    <dispatcher>ERROR</dispatcher> 
</filter-mapping> 

<filter> 
    <filter-name>sitemesh</filter-name> 
    <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>sitemesh</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>REQUEST</dispatcher> 
</filter-mapping> 


<!-- the name of this servlet maps to [servlet-name]-servlet.xml that will also be found in WEB-INF --> 
<servlet> 
    <servlet-name>base</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>base</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

基地

<?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:context="http://www.springframework.org/schema/context" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 


<!-- indicates the package(s) to be scanned to discover annotated controllers --> 
<context:component-scan base-package="com.execupros.rox.webapp.controllers" /> 

<!-- the mvc resources tag does the magic to skip static --> 
<mvc:resources mapping="/resources/**" location="/resources/" /> 



<!-- maps the JSP locations --> 
<bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver" > 
     <property name="prefix"> 
      <value>/WEB-INF/html/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
</bean> 

<!-- wires up commons upload --> 
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" /> 


<!-- define interceptors to be applied to all annotated controllers. --> 
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" > 
</bean> 
<bean id="annotationMapper" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> 
    <property name="interceptors"> 
     <list> 
      <!-- <ref bean="authInterceptor"/> --> 
      <ref bean="userContextInterceptor" /> 
     </list> 
    </property> 
</bean> 



<!-- <bean id="authInterceptor" class="com.execupros.rox.webapp.interceptors.AuthenticationInterceptor" /> --> 
<bean id="userContextInterceptor" class="com.execupros.rox.webapp.interceptors.UserContextInterceptor" /> 

正如我在拉等資源的例子這在默認的裝飾器上。

<script src="<c:url value="/resources/js/functions.js" />" type="text/javascript"></script> 

這似乎只當你刷新頁面的情況發生,並且它決定加載或不負載在/資源問候任何零星的。

+0

也許它與你的shiro過濾器有關,仔細檢查你的url映射和過濾邏輯。 –

回答

0

我能找到的唯一答案是將資源移出應用程序,這是我們能夠100%正確加載它們的唯一方法,換句話說,我們拿走了資源並創建了一個過濾器在Apache中拉動那些通過Apache服務的資源,而不是從tomcat服務它們。

RewriteCond $1 ^/(?!javascript|uploads|styles|images|test?).*$ [NC] 
相關問題