spring mvc - How to access subdir within images folder (getting 404)? -


i've added new subdir within images folder , cannot new images resolve.

failed load resource: ... 404 (not found) http://localhost:8080/mywebapp/content/images/subdir/mysubdirimage.png

my directory structure:

src -- main    --java    --webapp      --content         --images    // <- these resolve           --subdir  // <- new subdir...resolve fail images 

i have tried adding following does't work:

    <mvc:resources mapping="/content/**" location="/content/" /> 

mvc-dispatcher-servelet.xml:

 <mvc:annotation-driven/>  <mvc:default-servlet-handler />  <mvc:resources mapping="/content/**" location="/content/" />  //<-- added this..no go!   <bean class="org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter" />  <bean class="org.springframework.web.servlet.view.internalresourceviewresolver">     <property name="prefix"><value>/web-inf/views/</value></property>     <property name="suffix"><value>.jsp</value></property> </bean> 

you halfway there mvc-dispatcher-servlet line added, need change to:

<mvc:resources mapping="/images/**" location="/content/images/" /> 

also try changing method in controller attempting access images like:

@requestmapping(value = "/staticimages", method = requestmethod.get)    public string showimage() {              return "/images/subdir/mysubdirimage.png"; 

}

and finally, example above try url (as doing above):

http://localhost:8080/mywebapp/images/subdir/mysubdirimage.jpg 

you should able access images through @requestmapping pattern defined in controller. example, using example gave above, enter url:

http://localhost:8080/mywebapp/staticimages  

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -