这是jsp页面中一个调用get url的锚标记,从这个url我转发到post请求 CALL1 call1url在控制器中点击了一个get请求
@RequestMapping(value = "/call1url", method = RequestMethod.GET)
public String make(HttpServletRequest request) {
return "forward:/manctril";
}
转发到控制器中的帖子请求
@RequestMapping(value = "/main", method = RequestMethod.POST)
public String make2(HttpServletRequest request) {
return "forward:/dash";
}
尝试执行上述操作会返回类似于
的错误There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'GET' not supported
我的尝试是否可行,或者是否失败
答案 0 :(得分:0)
我不认为可以使用redirect or forward
从服务器进行GET到POST调用,您需要重新设计您的解决方案。您可以尝试使用以下方式实现它:
一个。你锚定Tag使用JS或AJAX对控制器进行POST调用,然后从一个POST到另一个POST可以完成,如下所示通过设置请求属性
request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.TEMPORARY_REDIRECT);
@RequestMapping(value = "/call1url", method = RequestMethod.POST)
public String make(HttpServletRequest request) {
request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.TEMPORARY_REDIRECT);
return "forward:/main";
}
@RequestMapping(value = "/main", method = RequestMethod.POST)
public String make2(HttpServletRequest request) {
return "dash";
}
湾您的锚点标记应该转到GET
调用,该调用应该呈现一个jsp / html页面然后autosubmit
jsp作为POST在页面/正文加载,如下所示,
<body onload="document.forms['redirectToURLForm'].submit()">
<form:form method="POST" id="redirectToURLForm"
name="redirectToURLForm" action="main">
</form:form>
</body>
这将调用POST
/main
方法。