當我嘗試加載http://localhost:8080/people
時,我收到一個404頁未找到的錯誤。彈簧servlet映射不起作用
這是我的servlet映射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>
這是我如何理解它的工作原理:
一個URL請求http://localhost:8080/people
會由servlet「春天裏」被截獲,並調用類org.springframework.web.servlet.DispatcherServlet
這是正確的嗎?
我是否需要一些額外的配置才能正確加載此類?
更新:
這裏是控制器:
@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/";
}
}
什麼是'people'?它是JSP頁面嗎?如果沒有,那麼沒有什麼可顯示的,你會看到一個_blank頁面。 –