jlars62
jlars62

Reputation: 7353

Can I tell spring to ignore query parameters?

If I submit this form:

<form id="confirmForm" method="POST">
    <input type="hidden" name="guid" value="guidval"/>
</form>

to this url:

/AltRT?guid=guidval

mapped to this controller method:

@RequestMapping(method = RequestMethod.POST)    
public String indexPost(@RequestParam String guid)

I am getting both values for my guid. So the value of guid is guidval,guidval. I would like to only get the value from the form.

Is there any way tell Spring to ignore query string parameters?

EDIT for more clarification: The query string is left over from another (get) request. So, if I could clear the query string that would work as well. Also, I do not want edit the name of the form input because I want this post endpoint to be available to other services without having to change them as well.

Upvotes: 6

Views: 3393

Answers (1)

Dino Tw
Dino Tw

Reputation: 3321

You cannot do so because the query string will be sent in the HTTP message body of a POST request, http://www.w3schools.com/tags/ref_httpmethods.asp

There are two ways I could think of now

  1. set the form attribute action

    <form id="confirmForm" method="POST" action="AltRT">
        <input type="hidden" name="guid" value="guidval" />
    </form>
    
  2. convert the form data into JSON object to send it over and then catch it with @RequestBody in Spring if you have to use the original URL.

Upvotes: 1

Related Questions