|
-
Aug 9th, 2006, 07:31 PM
#1
Thread Starter
Fanatic Member
Spring's DispatcherServlet noHandlerFound
I've got a simple application and I can't get it to work. I have HomeController in com.springinaction.training.mvc that looks like
Code:
public class HomeController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
return new ModelAndView("home", "message", greeting);
}
private String greeting;
public void setGreeting(String greeting) {
this.greeting = greeting;
}
}
Now for my web.xml, I have
Code:
<web-app>
<servlet>
<servlet-name>training</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>training</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
and for training-servlet.xml, I have
Code:
<bean name="/home.htm"
class="com.springinaction.training.mvc.HomeController">
<property name="greeting">
<value>Welcome to Spring Training!</value>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
and my home.jsp is
Code:
<html>
<head><title></title></head>
<body>
<h2>${message}</h2>
</body>
</html>
What am I missing here? Coz, I get a
Code:
WARNING: No mapping for [/SpringInAction/home.htm] in DispatcherServlet with name 'training'
Last edited by nebulom; Aug 11th, 2006 at 11:54 PM.
-
Aug 10th, 2006, 09:27 AM
#2
Re: Spring's DispatcherServlet noHandlerFound
You don't seem to have a RequestMapper (or whatever it's called) defined. Check the book again.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Aug 11th, 2006, 10:47 PM
#3
Thread Starter
Fanatic Member
Re: Spring's DispatcherServlet noHandlerFound
But CB, it's stated in the book that
One thing that may have struck you as odd is that instead of specifying a bean id for the HomeController bean, we’ve specified a name. And to make things even weirder, instead of giving it a real name, we’ve given it a URL pattern of “/home.htm”. Here the name attribute is serving double duty as both the name of the bean and a URL pattern for requests that should be handled by this controller. Because the URL pattern has special characters that are not valid in an XML id attribute—specifically, the slash (/) character—the name attribute had to be used instead of id.
When a request comes to DispatcherServlet with a URL that ends with “/home.htm”, DispatcherServlet will dispatch the request to HomeController for handling. Note, however, that the only reason that the bean’s name attribute is used as the URL pattern is because we haven’t configured a handler mapping bean. The default handler mapping used by DispatcherServlet is BeanNameUrlHandlerMapping, which uses the base name as the URL pattern.
I don't know if I understand it write that if the base URL lasted with /home.htm, the Dispatcher will dispatch it to homeController as the default UrlHandler is BeanNameUrlHanderMapping. I'm sorry for bothers, this may not be a case of Spring Framework but how well I understand English. I hardly speak/understand english btw, so sorry again.
-
Aug 11th, 2006, 11:54 PM
#4
Thread Starter
Fanatic Member
Re: Spring's DispatcherServlet noHandlerFound
Opps, sorry again. But I recently edited the servlet.xml to have a SimpleUrlHandlerMapping but I assume to be BeanNameUrlHanderMapping. I commented the
Code:
<!-- <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/hello.htm">springAppController</prop>
<prop key="/home.htm">homeController</prop>
</props>
</property>
</bean> -->
and it works now. Thanks CB, that directs me to look into handlerMapping.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|