-1


Is it possible to avoid the form action url from getting appended to the url in the address bar.?
Or how can i remove it in the end?
Ex :
1) Landing page url : abc.net. Its a JSP page. Clicked a button on this page.
2) Lands into another JSP page containing fields along with SUBMIT and CANCEL.
3) On clicking submit in this page,through a form action url specified, a servlet gets called and
url gets changed to abc.net/submit_click_action.
In this servlet, after processing, through the RequestDispatcher, i am making another servlet call,which gets me back to the landing JSP page.
But the url that i see in the address bar is : abc.net/submit_click_action.
Is there a way to avoid adding that 'submit_click_action' being appended to the address bar?
Or how can i remove it in the end?
I read about Pushstates in here: Stackoverflow. I am not sure if i need to use this.
Please help.

Community
  • 1
  • 1
Kavisha
  • 155
  • 1
  • 10

2 Answers2

0

A successful POST request should redirect to another URL. It shouldn't forward to another servlet. This allows the user to safely bookmark or refresh the page: the displayed URL in the address bar will be the page obtained by the redirect, using GET.

Read https://en.wikipedia.org/wiki/Post/Redirect/Get

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Thanks! I was searching around for removing the action url part from the url. Didnt realise it had something to do with Post-Redirect-Get. – Kavisha Jun 20 '15 at 15:33
0

A forward and a redirect are different things. And what is displayed in the URL bar of the browser is the last request that the browser has sent to server.

What happened :

  • you clicked on a submit button and brownser posted the form to an URL
  • in the servlet processing the request, you forwarded to another page - the browser was not notified of that

=> that's the reason why the URL bar still display the action URL

You should have done a redirect to the URL of the destination page. It is called the Post-Redirect-Get pattern :

  • the displayed URL is the correct one allowing the user to bookmark the page
  • if user clicks on the browser back button, he will never receive the ugly message "Do you really want to send again ...?" : because of the redirect, the POST has been replaced in browser history
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252