Shashwati Panigrahi wrote:
>
> Hi All,
>
> I am describing my situation below.
> I have a page called AddTicket.jsp, which sends all the ticket related data
> entered by the user to the servlet AddTicket.java.
>
> Now AddTicket.java creates a new ticket id by fecthing the maximum ticket id
> from the database and adding 1 to it.
>
> Then AddTicket.java inserts the record which consists of parameters received
> from the jsp as well as the ticket_id generated. If the insert is successful
> then it sends a message to the message page using the following code
>
> ServletContext sc=getServletContext();
> RequestDispatcher rd = sc.getRequestDispatcher(/jsp/Message.jsp);
> rd.forward(req,res);
>
> Now when the record is inserted then the Message is displayed on the message
> page whereas the URL on the browser is still that of the servlet.
>
> When I press F5 at this juncture, the servlet AddTicket re-executes thus
> creating another record with the next ticket id but all the data is same as
> the previous one. I want to prevent executing this servlet at this point
> when I refresh the page. What should I do and how should I go about it.
>
> I hope someone can help me fast
This is a situation where you could use a redirect instead of a forward:
response.sendRedirect(request.getContextPath() + "/jsp/Message.jsp");
This way, the browser knows that you switch to another page to display
the result and changes the URL in the address field. If the user reloads
the page, only the result page will be requested again. Note though,
that you must save the result as session scope objects, or send add
it as a query string in the redirect URL; request scope objects are
not available to the JSP page when you use redirect, since the JSP page
is invoked by a new request in this scenario.
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets