I have created one JSP page to insert user information and to show inserted info:
To get my insert data page I have a link eg: mysite/insertInfo
First accept user information and validate them. If valid submit form.Else when validation errors has occured , redirect to same page and without losing any form datas. At servlet (or controller class) save data and redirect to same page. I used redirecting with jQuery as like below:
url = baseURL + "/saveUserInfo";
params = {};
params.name = $(".txtname').val();
params.email = $('.txtemail').val();
ajax(url, params, false, function(data) {
$('.form').empty();
if (data) {
// SHOW SUCCESS INFO
html = [];
html.push("<div>Success</div>");
$('. form').append(html.join(''));
}
});
Second, I will show these were inserted before. Yes, it was simple and fine.
My problems is that when the user go to page mysite/insertInfo again, there has a form with inserted data. No, I don't want to see them again. I don't want to redirect to another page eg: success.jsp . I only want to use one JSP file. As description of Resetting a multi-stage form with jQuery, I tested with it.
Like $('#myform').trigger("reset");
before submitting this form. It is fine and reset. But when I reached successful page and go back insert form page via link, I see form with previous inserted data. How to handle it? Any suggestions would be appreciated. I think my browser may cached it but I am not sure.