PDA

View Full Version : Getting another dispatcher for my image requests


Munncha
Apr 28th, 2006, 03:16 AM
Currently i'm using spring and velocity to develop a web app. I'm having some problems getting images to display correctly though. All the files referenced will follow this post.

Anyhow, this seems painfully easy so i know it's a simple matter, but i've been googling and searching for hours with little benefit.

I jsut need images to display in a simple webapp, almost exactly like the one in the velocity/spring walkthrough. The problem currently is:

2006-04-27 23:41:06,413 WARN [org.springframework.web.servlet.PageNotFound] - <N
o mapping for [/dig/cigtemp.png] in DispatcherServlet with name 'dig'>

This makes sense. The dispatcher servlet is getting a request for a page it has no mapping for. However, i just need the damned thing to go get it if it doesn't have a mapping. But, there's no controller that just moves stuff along, as a far as I know.

Most of the walkthroughs have talked about setting up an imageServlet thingie that just goes and gets images. However, i have no idea how to do this, and couldn't find much to help. I can initialize a new dispatcher servlet that handles all the requests with certain file names, but i still don't know how to tell it to just go get the thing.

My intuition says to kill the mapping of * to the dispatcher, but then it crashes since it cannot recognize /*.htm which it what i need...

What am i missing?

Anyhow, any help would be nice.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<!--
- Application context definition for "dig" DispatcherServlet.
-->

<beans>
<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.Velo cityConfigurer">
<property name="resourceLoaderPath">
<value>/</value>
</property>
</bean>


<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.Velo cityViewResolver">
<property name="prefix"><value>/WEB-INF/velocity/</value></property>
<property name="suffix"><value>.vm</value></property>
</bean>


<bean id="MainPageController" class="web.MainPageController">

</bean>

<bean id="DisplayPageController" class="web.DisplayPageController">
</bean>

<bean id="UploadPageController" class="web.UploadPageController">
<property name="filePath"><value>dig/WEB-INF/images/</value></property>
<property name="output"><ref bean="md"/></property>
<property name="image"><ref bean="img"/></property>
</bean>

<bean id="SearchPageController" class="web.SearchPageController">
<property name="output"><ref bean="md"/></property>
</bean>

<bean id="md" class="db.MyData">
<property name="filePath"><value>dig/WEB-INF/images/</value></property>
</bean>

<bean id="img" class="db.MyImage">
</bean>


<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsM ultipartResolver"/>



<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="mappings">
<props>
<prop key="/hello.htm">MainPageController</prop>
<prop key="/search.htm">SearchPageController</prop>
<prop key="/display.htm">DisplayPageController</prop>
<prop key="/upload.htm">UploadPageController</prop>
</props>
</property>
</bean>
</beans>

and my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>

<web-app>
<servlet>
<servlet-name>dig</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dig</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>
hello.htm
</welcome-file>
</welcome-file-list>

</web-app>