Question

I have a web application that I'm writing with a base of Spring, Sitemesh, JPA, and Shiro. This is actually my first go around with most of these frameworks as I have been using Struts/ibatis for a long time.

The problem that I'm getting is strange and I have done a few days of research and trial and error and found nothing. I have intermittent problems on page refresh in the browser where the resource loads get aborted. They seem to get partially loaded at times, and other times they are completely missing.

The server set up is tomcat/apache.

I have looked on the server side and there are no errors that I can see.

Here is code from my web.xml and my 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>

base

<?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" />

As an example I pull in resources like this on the default decorator.

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

This only seems to happen when you refresh the page, and what it decides to load or not load is sporadic in regards to anything under /resources.

Was it helpful?

Solution

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]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top