掲示板

Data gets added to the database on refreshing the page.

8年前 に Sham Bhujbal によって更新されました。

Data gets added to the database on refreshing the page.

New Member 投稿: 6 参加年月日: 15/05/22 最新の投稿
1, view .jsp
2. addProject.jsp


1. I have a form on addProject.jsp to make entry to a database.
2. On form submission data gets entered in database and page gets redirected to view.jsp.

3. Issue - Now on refreshing the view.jsp the previous data gets entered into the database again. I believe its from the request-parameters.
How can I avoid this entry into the database?
thumbnail
8年前 に Sampsa Sohlman によって更新されました。

RE: Data gets added to the database on refreshing the page. (回答)

Regular Member 投稿: 230 参加年月日: 07/09/27 最新の投稿
Hi Sham,

This is typical problem. I have seen payments screens where this has been solved just by warning user not to refresh. Anyway that would be lazy and bad implementation.

By default Liferay has some help to that. You can use liferay-portlet.xml parameter action-url-redirect and set that to true.

That causes Liferay to tell browser to do redirect between action request and render request. So if someone is going to refresh the page after that he is doing that only for render request and that should not be a problem. (Of course you have to user action requests to store data).

This is not robust solution either. To make robust solution you need to add also add extra hidden field form value with some counter/random number, which you also store to session. Then during the action request you verify that number is same and then remove value from session, if value is not at session or it is different then you know that there is double submit.
8年前 に Sham Bhujbal によって更新されました。

RE: Data gets added to the database on refreshing the page.

New Member 投稿: 6 参加年月日: 15/05/22 最新の投稿
Thanks alot.

I also found another way we can do,
-After doing our logic we can redirect to specified URL by using actionResponse.
actionResponse.sendRedirect(PortalUtil.getLayoutURL(themeDisplay.getLayout(),themeDisplay));
Here we are redirecting to the friendly url of that page.

Although <action-url-redirect> simple and easy to resolve the issue.