我有一个表单,我从表单中查询数据库,并将结果发布到另一个页面。然后我从查询结果中选择一条记录,它将我带回查询所在的页面,以便更新记录。SpringMVC HTTP状态405 - 不支持请求方法'POST'
我点击更新,它将我带回控制器,然后调用相同的方法首先调用查询,但是请求的参数现在是“更新”,因此它假设转到方法中的更新条件。看起来好像我不能重新提交页面到相同的URL映射。
控制器
@RequestMapping(value="citizen_registration.htm", method = RequestMethod.POST)
public ModelAndView handleRequest(@Valid @ModelAttribute Citizens citizen,
BindingResult result, ModelMap m, Model model,
@RequestParam(value="user_request") String user_request) throws Exception {
try{
logger.debug("In Http method for CitizenRegistrationController - Punishment Registration");
logger.debug("User Request Is " + user_request);
if(result.hasErrors()){
//handle errors
// return new ModelAndView("citizen_registration");
}else{
//check if its a save or an update
if(user_request.equals("Save"))
//do save
else if (user_request.equals("Query"))
//do query
else if (user_request.equals("Update"))
//do update
}
}
错误日志
34789 [http-bio-8084-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Bound request context to thread: [email protected]
34791 [http-bio-8084-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'crimetrack' processing POST request for [/crimeTrack/getCitizen/citizen_registration.htm]
34792 [http-bio-8084-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Testing handler map [org.springframework[email protected]3a089b3] in DispatcherServlet with name 'crimetrack'
34792 [http-bio-8084-exec-3] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Looking up handler method for path /getCitizen/citizen_registration.htm
34796 [http-bio-8084-exec-3] DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
34796 [http-bio-8084-exec-3] DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
34796 [http-bio-8084-exec-3] DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
34796 [http-bio-8084-exec-3] WARN org.springframework.web.servlet.PageNotFound - Request method 'POST' not supported
34796 [http-bio-8084-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'crimetrack': assuming HandlerAdapter completed request handling
34796 [http-bio-8084-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Cleared thread-bound request context: [email protected]
34796 [http-bio-8084-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Successfully completed request
34796 [http-bio-8084-exec-3] DEBUG org.springframework.web.context.support.XmlWebApplicationContext - Publishing event in WebApplicationContext for namespace 'crimetrack-servlet': ServletRequestHandledEvent: url=[/crimeTrack/getCitizen/citizen_registration.htm]; client=[127.0.0.1]; method=[POST]; servlet=[crimetrack]; session=[null]; user=[null]; time=[8ms]; status=[OK]
34796 [http-bio-8084-exec-3] DEBUG org.springframework.web.context.support.XmlWebApplicationContext - Publishing event in Root WebApplicationContext: ServletRequestHandledEvent: url=[/crimeTrack/getCitizen/citizen_registration.htm]; client=[127.0.0.1]; method=[POST]; servlet=[crimetrack]; session=[null]; user=[null]; time=[8ms]; status=[OK]
萤火
检查萤火我得到这个"NetworkError: 405 Method Not Allowed - http://localhost:8084/crimeTrack/getCitizen/citizen_registration.htm"
这应该是http://localhost:8084/crimeTrack
/citize n_registration.htm“`
getCitizen是我第一次执行查询时被带到的页面,它包含在url中。
我改变了JSP表单动作定义<form:form id="citizenRegistration" name ="citizenRegistration" method="POST" commandName="citizens" action="<%=request.getContextPath()%>/citizen_registration.htm">
然而,当我启动应用程序,使这个页面,我收到了请求:
HTTP Status 500 - /WEB-INF/jsp/citizen_registration.jsp (line: 31, column: 116) attribute for %>" is not properly terminated
您的处理程序方法已映射到citizen_registration.htm。你的控制器类映射到/ getCitizen – digitaljoel 2013-03-14 18:07:45
@digitaljoel是有单独的映射/ getCitizen,但我想要访问的映射是/ citizen_registration但是我看到getCitizen进入url我知道它必须与ContextPath做但我我不确定我是否正确配置它。我更新了在jsp – devdar 2013-03-14 18:10:33
@dev_darin中显示配置的问题,因为我怀疑action url会导致问题。在jsp中试试这个<%= request.getContextPath()%>/getCitizen/citizen_registration.htm“> – 2013-03-14 18:22:41