简体   繁体   English

SpringMVC HTTP状态405-请求方法'POST'不支持

[英]SpringMVC HTTP Status 405 - Request method 'POST' not supported

I have a form i query the database from that form and is posted to another page with the results. 我有一个表单,我从该表单中查询数据库,并将结果发布到另一页。 I then select one record from the query results and it takes me back to the page i made the query from so i can update the record. 然后,我从查询结果中选择一条记录,然后将我带回到进行查询的页面,以便我可以更新记录。

I click update which takes me back to the controller and to tahe same method first called to query, however the requested parameter is now 'update' so it is suppose to go to the update condition in the method. 我单击“更新”,这将带我回到控制器,并再次使用相同的方法进行查询,但是现在请求的参数为“更新”,因此假设要转到该方法中的更新条件。 It seems as though i cannot re-submitt the page to the same url mapping. 似乎我无法将页面重新提交到相同的URL映射。

Controller 控制者

   @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

                }
    }

Error log 错误日志

34789 [http-bio-8084-exec-3] DEBUG org.springframework.web.servlet.DispatcherServlet  - Bound request context to thread: org.apache.catalina.connector.RequestFacade@2ba3ece5
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.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@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: org.apache.catalina.connector.RequestFacade@2ba3ece5
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]

FireBug 火虫

Inspecting FireBug I got this "NetworkError: 405 Method Not Allowed - http://localhost:8084/crimeTrack/getCitizen/citizen_registration.htm" this should be http://localhost:8084/crimeTrack /citizen_registration.htm"` 检查FireBug,我收到此"NetworkError: 405 Method Not Allowed - http://localhost:8084/crimeTrack/getCitizen/citizen_registration.htm"这应该是http://localhost:8084/crimeTrack /citizen_registration.htm”

The getCitizen is the page i was taken to when the query was first executed it got included in the url. getCitizen是我第一次执行查询时转到的页面,它包含在url中。

I changed the jsp form action definition to <form:form id="citizenRegistration" name ="citizenRegistration" method="POST" commandName="citizens" action="<%=request.getContextPath()%>/citizen_registration.htm"> however when i start the application and make a request to this page i get: 我将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 
function submitPage(){
     document.getElementById("citizenRegistration").action="getCitizen/citizen_registration.htm";
     document.getElementById("citizenRegistration").target="_self";    
     document.getElementById("citizenRegistration").method = "POST";
     document.getElementById("citizenRegistration").submit();
}

you can call the method as mentioning the above. 您可以按上述方式调用该方法。 bind the function for your submit button using onclick 使用onclick绑定提交按钮的功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM