PDA

View Full Version : cannot get FrameworkServlet to work with servlet


mikeottinger
Aug 14th, 2007, 02:40 AM
Hello,

I'm working on a servlet (not struts) ajax backend. I'm trying to extend FrameworkServlet so that I can get dependancies in a more cleaner fashion, but I'm having a hard time of it. I think I'm almost there, I'm having a hard time figuring out what url my servlet is mapped to, here's the relevant configs:

web.xml

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListe ner</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml /WEB-INF/selectmax-servlet.xml</param-value>
</context-param>
<servlet>
<servlet-name>selectmax</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>selectmax</servlet-name>
<url-pattern>*.max</url-pattern>
</servlet-mapping>


selectmax-servlet.xml

<beans>

<bean id="selectmax" class="com.mitsubishi.incentiveadmin.servlet.SelectMaxSer vlet">
<property name="incentiveAdminDao" ref="adminDao"/>
</bean>

</beans>


The urls I try are http://localhost:8080/foo/offerid.max and I receive

WARNING: No mapping for [/foo/offerid.max] in DispatcherServlet with name 'selectmax'
Aug 13, 2007 11:24:28 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping for [/foo/offerid.max] in DispatcherServlet with name 'selectmax'


any ideas?? Thanks!

A Kumar
Aug 14th, 2007, 04:32 AM
Where is your url mapping beans...

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="urlMap">
<map>
<!--
<entry key="mapping request ">
<ref bean="selectmax"/>
</entry>

</map>
</property>


</bean>


Just have a look at other handlermappings....like AbstractUrlHandlermapping,etc to suit ur requirements..

mikeottinger
Aug 14th, 2007, 12:07 PM
Great, thanks for the help. I added a SimpleUrlHandlerMapping and got it to go to my servlet. But then I got: No adapter for handler [com.myservlet@121df2a]: Does your handler implement a supported interface like Controller?

So I went ahead and had my servlet implement Controller, thus causing my handling code to go through the ModelAndView handleRequest method. This whole direction seems to be pushing me towards Spring MVC when I'm really trying to keep this a straight servlet-based solution. Is there anyway to get this all working without implementing Controller?

Thanks..

Jörg Heinicke
Aug 14th, 2007, 02:35 PM
I wonder why you need DispatcherServlet if you do not want Spring MVC!?

Joerg

mikeottinger
Aug 14th, 2007, 04:45 PM
I figured the dispatch servlet was needed to get my request into the Spring-manged servlet. I see a lot of references to people using the FrameworkServlet as a superclass in their servlets, but I haven't seen any definitive examples of it. I'm right now going the route of pulling my dependencies out using the WebApplicationContextUtils approach, it works but I thought there a cleaner approach that could come from the FrameworkServlet, does anyone have experience using this? Thanks for the replies by the way.

Jörg Heinicke
Aug 14th, 2007, 06:26 PM
But I guess you would go with your own servlet extending FrameworkServlet instead of DispatcherServlet. If you are brave enough you might have a look at how we did it in Cocoon (http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/servlet/): SitemapServlet uses RequestProcessor uses WebApplicationContextUtils.

Joerg

mikeottinger
Aug 15th, 2007, 12:26 AM
great, I'll take a poke around. Thanks for the help again