Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to prevent double data processing on page reload in jsp  RSS feed

Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
<!-- This html body content depends on displayBean -->
===============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))
else if (actionName != null && !"".equals (actionName) && "update".equalsIgnoreCase (actionName))



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.
Author and ninkuma
Posts: 66429
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!