*
The moose likes JSP and the fly likes How to prevent double data processing on page reload in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to prevent double data processing on page reload in jsp" Watch "How to prevent double data processing on page reload in jsp" New topic
Author

How to prevent double data processing on page reload in jsp

Sarvya padwal
Greenhorn

Joined: Aug 16, 2012
Posts: 9
Actually I have written one scriplet tag in jsp.
In that tag, I am calling method on one java that takes Request,response parameters and returns one bean.
But when I reload the page, request.getParameter() gives me same value as before and that leads to double data processing.
How can I prevent this?

===============My main page starts======================
<%@ include file="/jsp/header/mainHeader.jsp"%>
<%
MyClass myClass = MyClass ();
myClass .execute(request,response);
DisplayBean displayBean = myClass .getDisplayBean();
%>
<Html>
<body>
<!-- This html body content depends on displayBean -->
</body>
</html>
===============My main page ends======================

actually one another jsp page is sending request to this page,
In that page, I am submitting one form which has method="POST"
and that form sends one parameter named "actionName"

as soon as my main page encounters scriplet, it calls execute method
content inside execute method is:
-------------------------------------------------------------------------------------------------------------------------------
public void execute (HttpServletRequest request, HttpServletResponse response)
{
String actionName = request.getParameter ("actionName");
DisplayBean displayBean = new DisplayBean();
if (actionName != null && !"".equals (actionName) && "add".equalsIgnoreCase (actionName))
{
displayBean.processContent("add");
}
else if (actionName != null && !"".equals (actionName) && "update".equalsIgnoreCase (actionName))
{
displayBean.processContent("update");
}

setDisplayBean(displayBean);
}

----------------------------------------------------------------------------------------------------------------------------

Main Issue is:
when I reload the page, request.getParameter("actionName") returns same string as prevois one(eg: "add")
and this leads to double processing.

Please help me to resolve this issue.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Start by following modern best practices. That means no scriptlets in the JSP page, and structuring the controllers correctly.

Please read this article and pay particular attention to the PRG pattern.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to prevent double data processing on page reload in jsp