Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 698
jlars62 Avatar asked Nov 10 '22 12:11

jlars62


1 Answers

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.

like image 150
Dino Tw Avatar answered Nov 14 '22 21:11

Dino Tw