• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing from GET to POST  RSS feed

 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a page that takes its parameters from the URL - a GET. Once the page is loaded from the GET parameters, when a user submits information, it's done via a POST. The trouble is that the browser doesn't seem to get rid of the GET parameters in the URL (All postings are made to the same page). In actual fact, the POST parameters don't seem to be there at all. I'm doing it this way so the page can be pre-loaded by clicking on a link.
Is this a bug, or am I doing something wrong?
What's the best way of going from a GET to a POST? I guess that's really the question.
example:
fireflyclient.jsp?designID=2&templateID=5
loads the page, then a user clicks on the submit button to pass details into the system (method=POST).
fireflyclient.jsp?designID=2&templateID=5
stays in the URL and seems to be causing problems.
Any help is greatly appreciated.
Cheers,
Steve
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something is bizarre. Your POST shuold be to the URL specified in the action of the form tag, and contain info from form elements.
How are you setting the action attribute of the form? Are you accidentally setting it up to to use the same URL and params as the JSP that contains it?
 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,
The page is called fireflyclient.jsp and can be called by passing parameters into the URL which are collected using:
fireflyclient.jsp?designID=2&templateID=3
so the code is:
String designID = request.getParameter("designID");
String templateID = request.getParameter("templateID");
...
the page shows a form:
<form action="./fireflyclient.jsp" method=post>
<input type="hidden" name="designID" id="designID" value="2">
...
</form>
but when I submit the form, the parameters are not removed from the URL and seem to get collected again using the above parameter requests. I thought JSP would distinguish between a POST and a GET, but it just seems to be getting confused - I'm not sure if I'm doing something really stupid.
I hope this clarifies. Thanks for your help.
Cheers,
Steve
 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to clarify a bit more, the URL parameters are only used to initially load the page with the right information - the page uses POSTs after that.
Steve
 
Jeffrey Spaulding
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks odd to me, but you could try to remove the obsolet ./ before the jsp's name.
My 2 ct
 
Steve Wood
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I've solved the problem by changing the post parameter names to something different from the get parameters.
i.e.
GET method - loadServiceID (because it's passed in the URL to load the page)
POST method - serviceID (so it's not mistaken for the above)
Basically, I test to see if a certain parameter is passed to the page - this identifies which method the user used to load the page.
submissionType value="post"
i.e. I have a hidden form value that is only passed when you post the form. When the page is loaded from the URL parameters, the parameter is not given - this makes the distinction. I realise someone could append a 'submissionType=post" to the URL, and it would bugger things up, but I'm not too worried about that.
I realise this isn't really the best way of doing things, but it works.
Cheers,
Steve
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!