-1

i have signup page when i first submitting the data in form action i am sending it to a servlet before submiting my url is **Localhost:\Shop

**

<form action="signup" method="post">

and in this servlet i have businesses logic after submitting it i am forwarding it to my index page by

` request.getrequestdispatcher("index.jsp").forward(request,response);

now my URL is localhost:\Shop\SignUp now when i refresh this page it gives me warning

Confirmation Form Resolution

How do i avoid this problem ????

TechChain
  • 8,404
  • 29
  • 103
  • 228

1 Answers1

1

It is because you are posting the same request to the server as you are using RequestDispatcher method.

You need to understand the differences between RequestDispatcher.forward() vs HttpServletResponse.sendRedirect()

So you need to use the sendRedirect() method to create a new request

response.sendRedirect("index.jsp");

Hope this helps!!

Community
  • 1
  • 1
Santhosh
  • 8,181
  • 4
  • 29
  • 56
  • Sir but i'm setting attribute in the request if use Sendredirect i will not be able to set the attribute – TechChain May 02 '14 at 09:45
  • You can indeed set the attribute . But you need to pass the value as the value as `query string` . (i.e) however a bad idea . but you will get the warning window for `forwarding` , but that wont impact your result – Santhosh May 02 '14 at 09:47
  • actually i have function Boolean add_customer() which returns true if record successfully inserted i am passing that true value to jsp page through setting the attribue in request.i am generating a pop up on home page if record inserted successfully. – TechChain May 02 '14 at 09:55
  • so you dont want the pop-up to be shown after you reload every time , so you can set the value in the query string like this `response.sendRedirect("index.jsp?booVal="+valueHere);` – Santhosh May 02 '14 at 09:58
  • Ok and who do i get that value from url – TechChain May 02 '14 at 09:59
  • It is same as you done for the previous case . you can get the value from this `booVal` attribute . For example , if you use EL like ${booVal} – Santhosh May 02 '14 at 10:01
  • what kind of syntex is this i have never studied before can you write down the complete syntex – TechChain May 02 '14 at 10:15
  • that is expression language . if you are using java codes in your jsp [Read this](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files) – Santhosh May 02 '14 at 10:30