当我尝试加载http://localhost:8080/people
时,收到404找不到错误的页面。
这是我的weblet中的servlet映射:
<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>
以下是我理解它的工作原理:
servlet“spring”将拦截对http://localhost:8080/people
的url请求,并调用类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/";
}
}
答案 0 :(得分:1)
您是否有controller
支持来支持您的GET
回复?
像这样的东西
@Controller
@RequestMapping(value = "/people")
public class LoginController {
@RequestMapping(value = "/i_am_here", method = RequestMethod.GET)
public String firstForm() {
return "SHOW_ME_THE_JSP_PAGE";
}
}
根据以上示例,这将使您的获取URL请求如 - &gt; / people / i_am_here
将调用方法,并且可以在JSP
中发回回复。
Checkout this example under Github
https://github.com/hth/StatusInvoke/blob/master/src/com/example/UserController.java