Question

I'm having a 'weird' issue in serving static content from my webapp using a Spring-Hibernate setup.

I have a (small) webapp that uses the DispatcherServlet to serve any url like this: /coverpage/* .The default servlet mapping is set to /static/*

Example:

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/static/*</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/coverpage/*</url-pattern>
</servlet-mapping>

In my jsp's the static content (images/js/css) is written like this:

<spring:url value="/static/styles/js/jquery-1.4.2.min.js" />

I have 4 pages in the webapp: index.jsp, new.jsp, error.jsp and includes.jsp (which isn't an actual page, duh) and a mapping for /process which returns PDF content or validation-errors when entered incorrect data.

This setup seems to work fine in my webapp.

Now for the weird part: I have deployed the same webapp on another Tomcat instance and changed the ports so they can run simultaneously and now the references to static content are only working half the time. Only the mapping for /new (aka new.jsp) can find the static content. The rest fails to load it.

Differences between the 2 instances

  • Tomcat version (original runs on 6.0.29, second instance runs on 6.0.33)

  • Tomcat ports

  • Database connection (original goes to PROD db, second instance goes to TEST db - both databases are the same)

Here's my web.xml

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

<display-name>Coverpage creator</display-name>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/static/*</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/coverpage/*</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>SetUTF8EncodingFilter</filter-name>
    <filter-class>be.coverpagecreator.filter.SetUTF8EncodingFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>SetUTF8EncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>


<security-constraint>
    <web-resource-collection>
        <web-resource-name>Coverpage creator</web-resource-name>
        <url-pattern>/coverpage/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>cpcreator</role-name>
    </auth-constraint>
</security-constraint>

<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Coverpage creator</realm-name>
</login-config>

<security-role>
    <description>The role that is required to create coverpages</description>
    <role-name>cpcreator</role-name>
</security-role>

</web-app>

And dispatcher-servlet config

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.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">

<import resource="application-context.xml"/>

<mvc:annotation-driven />

<mvc:interceptors>
    <bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
        <property name="sessionFactory" ref="sessionFactory" />
        <property name="singleSession" value="false" />
    </bean>
</mvc:interceptors>

<context:component-scan base-package="be.coverpagecreator" />

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
  <property name="prefix" value="/WEB-INF/jsp/"/>
  <property name="suffix" value=".jsp"/>
</bean>

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="defaultEncoding" value="UTF-8" />
    <property name="useCodeAsDefaultMessage" value="false" />   
    <property name="basenames">
        <list>
            <value>/WEB-INF/messages/global</value>
            <value>/WEB-INF/messages/messages</value>
        </list>
    </property>
</bean>

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver" />
</beans>
Was it helpful?

Solution

The problem was with the Tomcat version. I tried to run the second instance on a newly downloaded 6.0.29 Tomcat instead 6.0.33 and it seems to work fine. I'm gonna go through the Tomcat changelogs to try and find what caused this... If I find anything, I'll report back here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top