我是spring mvc的新手,我不明白如何使用注释@RequestMapping。 这是控制器登录的代码:
@Controller
@RequestMapping(value="/")
public class LoginController {
protected final Logger log = Logger.getLogger(LoginController.class);
@Autowired // The authenticate service is automatically injected into this controller
private AuthenticateService service;
@RequestMapping(value = "{pathLogin}", method = RequestMethod.GET)
public String initFrom(@PathVariable("pathLogin") String path) {
log.info("Return on log view...."+path);
return "login";
}
@RequestMapping(value = "{pathOnSubmit}", method = RequestMethod.POST)
public String onSubmit(@RequestParam("username") String username,
@RequestParam("password") String password, @PathVariable("pathOnSubmit") String path, HttpServletRequest request) {
String message = "Invalid credential or Inexistent Username";
if(!service.authentification(username, password)) {
path = "login";
return "login";
}else {
path = "homePage";
return "homePage";
}
}
login.jsp中的表单是:
<form method="post" action="">
//here some input for the form
</from>
当我在网址中发出GET
请求时:"http:/...../Project_administration/login.htm"
一切都没问题。但是当我提交POST
请求时,如果我输入了正确的用户名和密码,则在控制器中执行ELSE block
并且请求在"/WEB-INF/jsp/homePage.jsp"
InternalResourceView
中转发。问题是网址,"http:/...../Project_administration/homePage.htm"
没有更改。我不知道为什么。
有人可以帮忙吗?
谢谢......