Spring Static Resource Mapping -


i have been followed error since started using spring can't handle static content

my dispatcher-servlet configuration

    <beans xmlns="http://www.springframework.org/schema/beans"        xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"        xmlns:p="http://www.springframework.org/schema/p"        xmlns:aop="http://www.springframework.org/schema/aop"        xmlns:mvc="http://www.springframework.org/schema/mvc"        xmlns:tx="http://www.springframework.org/schema/tx"        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/aop                              http://www.springframework.org/schema/aop/spring-aop-2.5.xsd                             http://www.springframework.org/schema/tx                             http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">     <import resource="applicationcontext.xml"/>     <bean id="viewresolver"           class="org.springframework.web.servlet.view.internalresourceviewresolver"           p:prefix="/web-inf/jsp/"           p:suffix=".jsp" />     <mvc:resources mapping="/captcha/*" location="/resources/captcha/" />     <mvc:annotation-driven />     <mvc:default-servlet-handler/> </beans> 

my web configuration

<?xml version="1.0" encoding="utf-8"?> <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"              xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"              xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee              http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">     <context-param>         <param-name>contextconfiglocation</param-name>         <param-value>/web-inf/applicationcontext.xml</param-value>     </context-param>     <listener>         <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>     </listener>      <context-param>         <param-name>log4jconfiglocation</param-name>         <param-value>/web-inf/log4j.properties</param-value>     </context-param>      <listener>         <listener-class>org.springframework.web.util.log4jconfiglistener</listener-class>     </listener>     <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>/</url-pattern>     </servlet-mapping>     <session-config>         <session-timeout>             30         </session-timeout>     </session-config> <servlet-mapping>         <servlet-name>default</servlet-name>         <url-pattern>*.css</url-pattern>     </servlet-mapping>     <servlet-mapping>         <servlet-name>default</servlet-name>         <url-pattern>*.js</url-pattern>     </servlet-mapping>     <servlet-mapping>         <servlet-name>default</servlet-name>         <url-pattern>*.js</url-pattern>     </servlet-mapping>     <servlet-mapping>         <servlet-name>default</servlet-name>         <url-pattern>*.gif</url-pattern>     </servlet-mapping>     <servlet-mapping>         <servlet-name>default</servlet-name>         <url-pattern>*.jpg</url-pattern>     </servlet-mapping>     <servlet-mapping>         <servlet-name>default</servlet-name>         <url-pattern>*.png</url-pattern>     </servlet-mapping> <welcome-file-list>         <welcome-file>login.jsp</welcome-file>     </welcome-file-list> </web-app> 

finally image want add

<img src="<c:url value="/resources/captcha/13.png"/>"/> 

but log displays this:

01:19:10,801 debug requestmappinghandlermapping:220 - looking handler method path /resources/captcha/35.png

01:19:10,803 debug requestmappinghandlermapping:230 - did not find handler method [/resources/captcha/35.png]

01:19:10,803 debug simpleurlhandlermapping:169 - matching patterns request [/resources/captcha/35.png] [/**]

01:19:10,804 debug simpleurlhandlermapping:194 - uri template variables request [/resources/captcha/35.png] {}

01:19:10,805 debug simpleurlhandlermapping:124 - mapping [/resources/captcha/35.png] handlerexecutionchain handler [org.springframework.web.servlet.resource.defaultservlethttprequesthandler@eea824] , 1 interceptor

01:19:10,805 debug dispatcherservlet:912 - last-modified value [/project/resources/captcha/35.png] is: -1

01:19:10,805 debug dispatcherservlet:999 - null modelandview returned dispatcherservlet name 'dispatcher': assuming handleradapter completed request handling

01:19:10,806 debug dispatcherservlet:966 - completed request

am missing more configuration?

thanks

when try access /resources/captcha/13.png

it mapped default servlet virtue of

<servlet-mapping>     <servlet-name>default</servlet-name>     <url-pattern>*.png</url-pattern> </servlet-mapping> 

it not mapped /resources/captcha/ because resources looks paths have pattern of type http://localhost:8080/captcha/* , not ones http://localhost:8080/resources/captcha/* handle such requests, need have view resolver respond /resources/* pattern

something like

@requestmapping(path = '/resources/*') public object handler(){...} 

my guess want render png image static resource , should have <img src="<c:url value="/resources/captcha/13.png"/>"/>.

note: not sure suggested works or not. answering solely based on memory , have not tested of situations mentioned.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -