mardi 12 mai 2015

Spring MVC - @PathVariable -Failed to find resource

In my spring mvc demp project I am using path variable annotation. Controller looks like below.

    @Controller
    @RequestMapping(value = {"/", "/login"})
    public class HelloWorldController {

        @RequestMapping(method = RequestMethod.GET)
        public String helloWorld(final Model model) {
            model.addAttribute("message", "Hello World!");
            System.out.println("hello world");
            return "jsp/login.jsp";
        }

        @RequestMapping(value = "/{id}", method = RequestMethod.GET)
        public String getLoginId(@PathVariable final int id, final Model model) {
            model.addAttribute("message", "Hello World!");
            System.out.println("hello world 2" + id);
            return "jsp/login.jsp";
        }
    }

Now when I trying to access the below url http://localhost:9080/ExampleSpring/login the controller is going to login.jsp page. This is an expected result.

but when the url is changed to http://localhost:9080/ExampleSpring/login/9 I am getting the below error and java.io.FileNotFoundException: JSPG0036E: Failed to find resource /login/jsp/login.jsp

Could anybody please tell me the reason behind this?

Aucun commentaire:

Enregistrer un commentaire