6

From Spring Official Document, Spring 3 MVC look to be support nesting Request Mapping. http://static.springsource.org/spring/docs/3.0.0.RELEASE/spring-framework-reference/pdf/spring-framework-reference.pdf In page 448, they mentioned:

@Controller
@RequestMapping("/appointments")
public class AppointmentsController {
//...
    @RequestMapping(value="/new", method = RequestMethod.GET)
    public AppointmentForm getNewForm() {
        return new AppointmentForm();
    }
//...
}

(I have eliminated some code for readability) In such case, they claimed that a request to /appoinments/new will invoke the getNewForm method. However, it doesn't work with my local Google App Engine server (though GAE server works just fine with mapping that are not nested). I create an example controller like below:

@Controller
@RequestMapping("/basic.do")
public class HelloWorldController {
    @RequestMapping(value="/hello", method=RequestMethod.GET)
    public ModelAndView helloWorld() {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("basic/helloWorld");
        mav.addObject("message", "Hello World From Phuong!");
        return mav;
    }
}

but a request to /basic.do/hello always results in 404 error.

Wonder if anything wrong there? I'm using annotation-driven mode with *.do request handled by spring DispatchServlet.

0

1 Answer 1

15

try this

@Controller
@RequestMapping("/basic")
public class HelloWorldController {
    @RequestMapping(value="/hello.do", method=RequestMethod.GET)
    public ModelAndView helloWorld() {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("basic/helloWorld");
        mav.addObject("message", "Hello World From Phuong!");
        return mav;
    }
}

and try with the basic/hello.do url

The reason is that /basic.do/hello is not going to be handled by your dispatcher servlet as it is not an URL that ends in .do

BTW, .html extensions are nicer than .do, IMHO

Sign up to request clarification or add additional context in comments.

2 Comments

And no extension is nicer than .html
Actually "no extension" is nicer than .html ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.