-
RequestMapping question
Hi,
I'm new to Spring. So please be tolerant if I'm asking silly questions.
I'm trying to make a multiaction controller like as following:
Code:
@Controller
@RequestMapping("/action.do")
public class EditPo {
@RequestMapping("/new")
public String newPo(HttpSession session,ModelMap model)
{
return "form1";
}
@RequestMapping("/edit")
public String editPo(HttpSession session,ModelMap model)
{
return "form2";
}
}
I think I should be able to get form1 from http://localhost:8080/Webapp/action.do/new and form2 from http://localhost:8080/Webapp/action.do/edit. But instead I got HTTP 404 error and "WARNING: No mapping found for HTTP request with URI [/POTracking/servlet/action.do/new] in DispatcherServlet with name 'dispatcherServlet'" in console output. And what is even stranger is when I put http://localhost:8080/Webapp/action.do, I always got form1, no matter which method I put first in the src code.
My environment is eclipse 3.5, tomcat 5.5, spring 3.0.2. I put <context:component-scan base-package=... > in the dispatcherServlet-servlet.xml.
Thanks in advance for any suggestion.
-
Hi
The problem lies in your web.xml where you've mapped *.do to your dispatcher servlet.
There are two kinds of mappings in web.xml - extension based and url prefix based. If you want to map /action.do to class and /new | /edit to methods - please don't.
Either:
1) map *.do to DispatcherServlet in web.xml and then /po to class and /new.do | /edit.do to methods, or
2) map /po/* to DispatcherServlet in web.xml and then don't use @RequestMapping for controller class, but only /new and /edit for controller methods.
regards
Grzegorz Grzybek
-
Hi,
Thank you so much for your reply.
Both of you suggestions work. Problem solved.
I also tried this: map /servlet/* to DispatcherServlet in web.xml,
map /po to class and /new to method, /servlet/po/new works. But if I map /po.do to class and /new to method, /servlet/po.do/new doesn't work. It seems like if url in class RequestMapping has a extension, Spring won't look furthen into the url in method RequestMapping.