我试图让我的控制器将POST请求转发给另一个带有一些参数的控制器:
@RequestMapping(method=RequestMethod.POST)
public String processSubmit(@Valid Voter voter, BindingResult result,
//...
request.setAttribute("firstName", voter.getFirstName());
request.setAttribute("lastName", voter.getLastName());
request.setAttribute("ssn", voter.getSsn());
logger.info("VoterID exists, forwarding to /question/prepare");
return "forward:/question/prepare";
我面临的问题是/ question / prepare指向仅处理HTTP GET请求的Controller方法。
@RequestMapping(value="/prepare", method=RequestMethod.GET)
public String prepareVoterBean(@RequestParam String firstName,
@RequestParam String lastName, @RequestParam String ssn, Model model) {
logger.info("QuestionController got GET REQUEST for " + firstName + lastName + ssn);
VoterBean bean = new VoterBean();
bean.setFirstName(firstName);
bean.setLastName(lastName);
bean.setSsn(ssn);
model.addAttribute("questions",bean);
return "questionPage";
}
有没有办法将prepareVoterBean的请求作为HTTP GET请求转发?感谢。
答案 0 :(得分:3)
有没有办法将prepareVoterBean的请求作为HTTP转发 GET请求?
尝试使用redirect:
前缀。
return "forward:/question/prepare";
这不是POST。以下链接可能有用:"22.5.3 Redirecting to views" section。
答案 1 :(得分:-1)
@Midnight Blue ...
将退货类型更改为return "forward:/prepare";