Announcement Announcement Module
No announcement yet.
RequestMapping question Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • RequestMapping question

    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:

    public class EditPo {
    	public String newPo(HttpSession session,ModelMap model)
    		return "form1";
    	public String editPo(HttpSession session,ModelMap model)
    		return "form2";
    I think I should be able to get form1 from http://localhost:8080/Webapp/ and form2 from http://localhost:8080/Webapp/ But instead I got HTTP 404 error and "WARNING: No mapping found for HTTP request with URI [/POTracking/servlet/] in DispatcherServlet with name 'dispatcherServlet'" in console output. And what is even stranger is when I put http://localhost:8080/Webapp/, 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.

  • #2

    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 / to class and /new | /edit to methods - please don't.

    1) map *.do to DispatcherServlet in web.xml and then /po to class and / | / 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.

    Grzegorz Grzybek


    • #3
      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 / to class and /new to method, /servlet/ 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.