Reputation: 53786
When I try to load http://localhost:8080/people
I receive a 404 page not found error.
This is my servlet mapping iwthin web.xml :
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/people/*</url-pattern>
</servlet-mapping>
Here is how I understand it works :
A url request to http://localhost:8080/people
will be intercepted by the servlet "spring" and will invoke the class org.springframework.web.servlet.DispatcherServlet
Is this correct ?
Do I need some additional configuration in order for this class to be loaded correctly ?
Update :
Here is the controller :
@Controller
public class PersonController {
@Autowired
private PersonService personService;
@RequestMapping("/")
public String listPeople(Map<String, Object> map) {
map.put("person", new Person());
map.put("peopleList", personService.listPeople());
return "people";
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String addPerson(@ModelAttribute("person") Person person, BindingResult result) {
personService.addPerson(person);
return "redirect:/people/";
}
@RequestMapping("/delete/{personId}")
public String deletePerson(@PathVariable("personId") Integer personId) {
personService.removePerson(personId);
return "redirect:/people/";
}
}
Upvotes: 3
Views: 3538
Reputation: 4088
Do you have controller
backing to support your GET
response?
Something like this
@Controller
@RequestMapping(value = "/people")
public class LoginController {
@RequestMapping(value = "/i_am_here", method = RequestMethod.GET)
public String firstForm() {
return "SHOW_ME_THE_JSP_PAGE";
}
}
Based on above example, this will make your get URL request like -> /people/i_am_here
Method will be invoked and the response could be sent back in JSP
.
Checkout this example under Github
https://github.com/hth/StatusInvoke/blob/master/src/com/example/UserController.java
Upvotes: 2