I’m developing a web application with JSP and servlets.
In my JSP i have several forms, such as the following
<form method="post" action="quotation">
<input type="submit" name="addStep" value="Add a Step" class="noLabel" />
</form>
I’m using the “name” attribute of the form to know in my servlet’s doPost method which code I should call.
The problem is the following :
- I load my jsp in my web server
- I click on the “Add a step” button on my form => the correct code is applied
- If I reload the web page by pressing “enter” on the adress bar, the same code is applied again, because I guess that the addStep attribute is not reset on the Http request
Do you know how to reset the request attribut (here addStep) in order to prevent this behaviour to happen ?
Here is the doPost method:
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
request.setAttribute(DATABASE_ATT, databaseData);
this.getServletContext().getRequestDispatcher(VIEW)
.forward(request, response);
}
After the post, redirect (using
HttpServletResponse.sendRedirect()) to the page showing the form, so that a refresh will only reload the page containing the form, rather than re-submit the form.See http://en.wikipedia.org/wiki/Post/Redirect/Get