Search code examples
javapath-variables

Path Variable Causing 404



I'm adding a Path variableto receive value sent by URL. And this is my controller.

@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping(value = "/list/{field}", method = RequestMethod.GET)
    public void userList(Model model, @PathVariable("field") String field) {
        List<Users> userList = userDAO.searchAll();
        System.out.println("Condition "+field);
        model.addAttribute("userList", userList);
    }

}

But I'm getting a 404 error. browser screenshot

And this is my folder structure for jsp. JSP folder structure

Please help me to find out what is wrong here.
Thanks.


Edit : And also is there any chance that I can send empty path variable ex: http://localhost:8080/mvcquick/user/list and return to the same method?


Solution

  • system is looking for mvcquick/WEB-INF/jsp/user/list/n.jsp. I dont see this file.

    Please try this:

    @Controller
    @RequestMapping("/user")
    public class UserController {
    
        @RequestMapping(value = "/list/{field}", method = RequestMethod.GET)
        public String userList(Model model, @PathVariable("field") String field) {
            List<Users> userList = userDAO.searchAll();
            System.out.println("Condition "+field);
            model.addAttribute("userList", userList);
            return "user/list"; // added line. Alos return type to String
        }