Back Forum Reply New

Banging my head: No css or image mappings

How do I get my css files (and all my include files such as images and anything else I can think of) served up through tomcat using Spring?

I am using Spring 2.5 along w/ Tiles and I have my tiles working great.  But I just cannot get my css and image files accessed from the browser.

This is what I have for a directory listing via the war file:
tomcat/webapps/myapp/includes/css/*.css
tomcat/webapps/myapp/includes/images/*.png

(just FYI, I used to have these in the WEB-INF directory but that didnt work either).

Here is my web.xml:

Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;

lt;web-app version=quot;2.4quot;        xmlns=quot;xml/ns/j2eequot;        xmlns:xsi=quot;2001/XMLSchema-instancequot;        xsi:schemaLocation=quot;xml/ns/j2ee        xml/ns/j2ee/web-app_2_4.xsdquot; gt;
       lt;servletgt;    lt;servlet-namegt;myapplt;/servlet-namegt;    lt;servlet-classgt;org..web.servlet.DispatcherServletlt;/servlet-classgt;    lt;load-on-startupgt;1lt;/load-on-startupgt;       lt;/servletgt;
       lt;servlet-mappinggt;    lt;servlet-namegt;mayapplt;/servlet-namegt;    lt;ucl-patterngt;/lt;/ucl-patterngt;       lt;/servlet-mappinggt;
       lt;welcome-file-listgt;    lt;welcome-filegt;index.jsplt;/welcome-filegt;       lt;/welcome-file-listgt;
lt;/web-appgt;
Here is myapp-servlet.xml:

Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;beans xmlns=quot;schema/beansquot;      xmlns:xsi=quot;2001/XMLSchema-instancequot;      xsi:schemaLocation=quot;schema/beans      schema/beans/spring-beans-2.5.xsdquot;gt;       lt;!-- Tiles Definition --gt; lt;bean id=quot;tilesConfigurerquot; class=quot;org..web.servlet.view.tiles2.TilesConfigurerquot;gt; lt;property name=quot;definitionsquot;gt;    lt;listgt;         lt;valuegt;/WEB-INF/tiles-def/tiles-def.xmllt;/valuegt;         lt;/listgt;    lt;/propertygt; lt;/beangt;
lt;bean id=quot;viewResolverquot; class=quot;org..web.servlet.view.uclBasedViewResolverquot;gt; lt;property name=quot;requestContextAttributequot; value=quot;requestContextquot;/gt; lt;property name=quot;viewClassquot; value=quot;org..web.servlet.view.tiles2.TilesViewquot; /gt; lt;/beangt;  lt;!-- Services --gt; lt;bean id=quot;ModeManagerquot; class=quot;com.myapp.service.ModeManagerquot; factory-method=quot;createInstancequot;/gt; lt;bean id=quotropertiesManagerquot; class=quot;com.myapp.service.PropertiesManagerquot; factory-method=quot;createInstancequot;/gt; lt;bean id=quot;UserManagerquot; class=quot;com.myapp.service.UserManagerquot; factory-method=quot;createInstancequot;/gt;       lt;!-- Controllers --gt; lt;bean id=quot;MainpageControllerquot; class=quot;com.myapp.web.controller.MainpageControllerquot;gt; lt;property name=quot;propertiesManagerquot;gt; lt;ref bean=quotropertiesManagerquot;/gt; lt;/propertygt; lt;/beangt;  lt;bean id=quotropertiesControllerquot; class=quot;com.myapp.web.controller.PropertiesControllerquot;gt; lt;property name=quot;propertiesManagerquot;gt; lt;ref bean=quotropertiesManagerquot;/gt; lt;/propertygt; lt;/beangt;  lt;!-- the application context definition for the DispatcherServlet --gt;   lt;bean id=quot;uclMappingquot; class=quot;org..web.servlet.handler.SimpleuclHandlerMappingquot;gt;lt;property name=quot;mappingsquot;gt;lt;propsgt;lt;prop key=quot;/properties/*quot;gtropertiesControllerlt;/propgt;lt;prop key=quot;/main/*quot;gt;MainpageControllerlt;/propgt;lt;/propsgt;lt;/propertygt; lt;/beangt;  
lt;/beansgt;
Again, I want to stress that my jsp's are being utilized correctly with the Tiles functionality.  All of my data and page content is being displayed but CSS is not working and no images are being accessed.

This is the the code in my MAIN jsp file (that is used for all Tiles templates):

Code:
lt;headgt;
lt;titlegt;lt;tiles:getAsString name=quot;titlequot; /gt;lt;/titlegt;
lt;link rel=quot;stylesheetquot; type=quot;text/cssquot; hrcf=quot;lt;%= request.getContextPath()%gt;/includes/css/main.cssquot;/gt;
lt;/headgt;
So when the webpage is accessed, all my content is shown but this is the error I get out of Tomcat:
DEBUG from-8080-1 org..web.servlet.handler.SimpleuclH  andlerMapping - Looking up handler for [/includes/css/main.css]WARN from-8080-1 org..web.servlet.PageNotFound - No mapping found for from request with URI [/myapp/includes/css/main.css] in DispatcherServlet with name 'myapp'.

I've been banging my head on this all afternoon and any help would be GREATLY appreciated.

Thanks!

PAR

Hi,

lt;servlet-mappinggt;    lt;servlet-namegt;mayapplt;/servlet-namegt;    lt;ucl-patterngt;/lt;/ucl-patterngt;       lt;/servlet-mappinggt;

you have mapped the / as the pattern to be intercepted by the dispatcher servlet, hence you are having the problem.

there are many ways to solve this problem,

identify the pattern that your spring mvc/webflow uses and put a specific pattern instead of the slash for example have a pseudo pattern say /spring
hence your ucl would look like context/spring/whateverpattern
but the images and the css will still still be referred from your current includes directory.the other approach is to use an extension instead of the slash
for example

Code:
lt;servlet-mappinggt;    lt;servlet-namegt;mayapplt;/servlet-namegt;    lt;ucl-patterngt;*.dolt;/ucl-patterngt;       lt;/servlet-mappinggt;
ensure that all your spring ucls end with .do

you can also serve static data using a servlet if you want to,

Wow that worked right off the bat!  Thanks a lot!

I looked everywhere prior to creating this thread and just could not find the problem.  I knew is was something simple but didnt think it was that.

Again, thanks a lot!

PAR

Hi,

I have the same problem but I am using acegi security as well. So I think its filtering out some of my css. My servlet-mapping is as follows:
   lt;servlet-mappinggt;       lt;servlet-namegt;testlt;/servlet-namegt;       lt;ucl-patterngt;/*lt;/ucl-patterngt;   lt;/servlet-mappinggt;

My acegi  FilterChainProxy is as follows:
   lt;!--  This file handle the security configuration management provided by Acegisecurity --gt;   lt;bean id=quot;filterChainProxyquot; class=quot;org.acegisecurity.util.FilterChainProxyquot;gt;       lt;property name=quot;filterInvocationDefinitionSourcequot;gt;lt;valuegt;    CONVERT_ucl_TO_LOWERCASE_BEFORE_COMPARISON    PATTERN_TYPE_APACHE_ANT    /css/**=#NONE#    /css/*=#NONE#    /*.css=#NONE#    /**=fromSessionContextIntegrationFilter,logoutFilte  r,casProcessingFilter,anonymousProcessingFilter,se  curityContextHolderAwareRequestFilter,exceptionTra  nslationFilter,filterInvocationInterceptorlt;/valuegt;       lt;/propertygt;   lt;/beangt;

Any thoughts? Originally Posted by sami25Hi,
you have mapped the / as the pattern to be intercepted by the dispatcher servlet, hence you are having the problem.

there are many ways to solve this problem,

identify the pattern that your spring mvc/webflow uses and put a specific pattern instead of the slash for example have a pseudo pattern say /spring
hence your ucl would look like context/spring/whateverpattern
but the images and the css will still still be referred from your current includes directory.the other approach is to use an extension instead of the slash
for example

Code:
lt;servlet-mappinggt;    lt;servlet-namegt;mayapplt;/servlet-namegt;    lt;ucl-patterngt;*.dolt;/ucl-patterngt;       lt;/servlet-mappinggt;
ensure that all your spring ucls end with .do

you can also serve static data using a servlet if you want to,
¥
Back Forum Reply New