HTTP用SpringMVC状态405 - 请求方法“POST”不支持(SpringMVC HTT

2019-08-17 14:50发布

我有一个形式,我从形式查询数据库,并张贴到的结果的另一页。 然后我选择从查询结果中的一个记录,它把我带回到我的,所以我可以更新记录进行查询的页面。

我点击更新,其中把我带回到了控制器和塔河同样的方法首先调用查询,但是请求的参数现在是“更新”,因此它是假设去的方法更新条件。 它好像我不能再submitt页面相同的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: 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]

萤火

检查萤火我得到这个"NetworkError: 405 Method Not Allowed - http://localhost:8084/crimeTrack/getCitizen/citizen_registration.htm"这应该是http://localhost:8084/crimeTrack /citizen_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 

Answer 1:

function submitPage(){
     document.getElementById("citizenRegistration").action="getCitizen/citizen_registration.htm";
     document.getElementById("citizenRegistration").target="_self";    
     document.getElementById("citizenRegistration").method = "POST";
     document.getElementById("citizenRegistration").submit();
}

你可以调用方法提及上述内容。 绑定功能,为您的使用提交按钮的onclick



文章来源: SpringMVC HTTP Status 405 - Request method 'POST' not supported