我有一個表單,我從表單中查詢數據庫,並將結果發佈到另一個頁面。然後我從查詢結果中選擇一條記錄,它將我帶回查詢所在的頁面,以便更新記錄。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