【发布时间】:2016-11-21 14:57:03
【问题描述】:
您好,我在这个控制器中有一个有线行为。我有两种方法获取准备信息以显示在 html 表单和 POST 以获取提交:
控制器:
@Controller
public class NotificationController {
final String JSP_NOTIFICATION_01="pages/sendPush/createNotification";
final String JSP_NOTIFICATION_02="pages/sendPush/createNotificationStep2";
@RequestMapping(value ="/admin/notification/newNotification",method = RequestMethod.GET)
public String newNotification( Map<String, Object> model, HttpServletRequest request) {
//prepare info to fill html form
request.getSession().setAttribute("notificacion", notification);
return JSP_NOTIFICATION_01;
}
@RequestMapping( value ="/admin/notification/sendNotification", method = RequestMethod.POST)
public String saveNotification(@ModelAttribute("notForm") SendNotificationModel notForm,
Map<String, Object> model,HttpServletRequest request) {
//Get all information from HTML form
System.out.println("llego.."+resultado);
model.put("resultado", resultado);
return JSP_NOTIFICATION_02;
}
}
JSP
<form:form action="${pageContext.request.contextPath}/admin/notification/sendNotification" method="post" commandName="notForm">
<form:hidden path="clientName" />
<form:hidden path="clientCode" />
</tr>
<tr>
<td>topics:</td>
<td><form:select path="topics" items="${topicList}" /></td>
</tr>
<tr>
<td>users:</td>
<td><form:select multiple="true" path="users" items="${userList}" /></td>
</tr>
<tr>
<td>Tipo de despliege :</td>
<td><form:select path="tipoNotificacion" items="${tipoNotificacionList}" /></td>
</tr>
</table>
<tr>
<td colspan="2" align="center"><input type="submit" value="Enviar" /></td>
</tr>
</table>
</form:form>
提交POST方法后一如既往的接收请求,但是返回spring后抛出405错误:
HTTP Status 405 - Request method 'POST' not supported
type Status report
message Request method 'POST' not supported
description The specified HTTP method is not allowed for the requested resource.
我正在使用 Spring 4.1.3 和 tomcat8
谢谢!!!
【问题讨论】:
-
确保为您的 post 方法提供准确的参数
-
@koutuk 那会有什么不同?为什么错误的参数会导致 405?
标签: java spring spring-mvc