4

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.

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"`

The getCitizen is the page i was taken to when the query was first executed it got included in the 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:

HTTP Status 500 - /WEB-INF/jsp/citizen_registration.jsp (line: 31, column: 116) attribute for %>" is not properly terminated 
Mallikarjuna Reddy
  • 1,184
  • 2
  • 19
  • 33
devdar
  • 5,244
  • 23
  • 88
  • 152
  • 1
    your handler method is mapped to citizen_registration.htm. Is your controller class mapped to /getCitizen – digitaljoel Mar 14 '13 at 18:07
  • @digitaljoel yes there is a mapping separately for /getCitizen but the mapping i want to access is /citizen_registration however i am seeing getCitizen getting into the url i know it has to do with the ContextPath but i am not sure if i am configuring it correctly. I updated the question showing the configurations in the jsp – devdar Mar 14 '13 at 18:10
  • 1
    @dev_darin, As i suspect action url would the problem. In jsp try this /getCitizen/citizen_registration.htm"> – Mallikarjuna Reddy Mar 14 '13 at 18:22
  • @GMR yes thats the error there getCitizen is a mapping in the Controller however it is called from an href in one of the forms once that happens it appends itself to url's why and how do i solve this – devdar Mar 14 '13 at 18:24
  • 1
    @dev_darin it would be better , try to to submit the form in script. And in controller you no need to mention the htm extension, as it is optional and please cross verify the web.xml – Mallikarjuna Reddy Mar 14 '13 at 18:28
  • @GMR crimetrack *.htm – devdar Mar 14 '13 at 18:34
  • @GMR when you say submit the form in script do you mean using an ajax call? Do you have any examples of this? – devdar Mar 14 '13 at 18:35
  • @dev_darin, it is not ajax call, please check the provided answer – Mallikarjuna Reddy Mar 14 '13 at 18:50

1 Answers1

2
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

Mallikarjuna Reddy
  • 1,184
  • 2
  • 19
  • 33
  • i need some help here never used much jquery. I want when i click the update button that the page is submitted with citizen_registration url to the controller.This is what i have on the citizen_registration page. $('#update').bind('click', function() { submitPage(); }); update is a submit button will this work? – devdar Mar 14 '13 at 19:04
  • 1
    yes, You can do the same **or** can be mentioned directly in onclick attribute like `onclick="submitPage()"` – Mallikarjuna Reddy Mar 14 '13 at 19:08
  • how does it find he action to preform i know its a submit button and there is a submit definition there do all submits, target and method use the action url? – devdar Mar 14 '13 at 19:10
  • 1
    It's a JS inbuilt function. that will be the request. and it is same as click functionality.. check this once.. http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml – Mallikarjuna Reddy Mar 14 '13 at 19:15
  • I have just one problem with this how you i get the button value that was posted because i am preventing default on the button and i am using request.getParameter to get the button value. – devdar Mar 14 '13 at 19:56
  • how can i send the button value in the post as well? – devdar Mar 14 '13 at 19:56
  • can you look at this question for me http://stackoverflow.com/questions/15746371/springmvc-custom-collection-editor-not-returning-data-to-jsp?noredirect=1#comment22402937_15746371 – devdar Apr 02 '13 at 14:42