0

我有一个基于 Spring、Sitemesh、JPA 和 Shiro 编写的 Web 应用程序。这实际上是我第一次使用大多数这些框架,因为我已经使用 Struts/ibatis 很长时间了。

我遇到的问题很奇怪,我已经做了几天的研究和反复试验,但一无所获。在资源加载中止的浏览器中,我在页面刷新时遇到间歇性问题。他们似乎有时会部分加载,而其他时候则完全丢失。

服务器设置是tomcat/apache。

我查看了服务器端,没有看到任何错误。

这是来自我的 web.xml 和我的 base-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>

这似乎只在您刷新页面时发生,并且它决定加载或不加载的内容对于 /resources 下的任何内容都是零星的。

4

1 回答 1

0

The only answer I could find was to move the resources outside of the application, that was the only way we could get them to load correctly 100% of the time, in other words, we took the resources and created a filter in apache to pull in those resources to be served through apache as opposed to serving them from tomcat.

 RewriteCond $1 ^/(?!javascript|uploads|styles|images|test?).*$ [NC]
于 2014-02-03T22:43:45.077 回答