javamavenspring-mvcresin

Mapping Resources in dispatcher servlet (Resin Server)


This is my dispacter-servlet.xml file. When i deploy the project on resin pro 4.0.36 it loads my index page and the content BUT FAILS to load css files and images stored under the staticresources folder

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

<context:component-scan base-package="com.dogears" />


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

<import resource="classpath:beans.xml"/>

<mvc:resources mapping="/resources/**" location="/staticresources/" />
<mvc:annotation-driven />

Please can anyone tell me how to mapp my static resources folder, so that whenever the request is of the patter /resources/* it redirects the request to the static resources folder. the staticresources folder is in MyspringProject/src/main/webapps directory.


Solution

  • I finally found my solution. I had deployed my spring webapp in the webapps folder of the resin directory.

    I realised that <mvc:resource /> mapping tag does not work when you have deployed your spring app on resin server instead of tomcat.

    Hence i solved this by first creating a war file of my project and then extracted the war file on the desktop and later placed all the contents from the war file in the webapps/root (and not webapps folder) folder of resin directory. and then from my index page i used JSTL TAG to include the external stylesheet.

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <html>
    <head>
    
    <link rel="stylesheet" type="text/css" href="<c:url  value="/staticresources/externalcss.css"/>">
    
    </head>
    <body>
    <h2 class="text_style">Hello World!</h2>
    </body>
    </html>
    

    IT WORKS !!!