• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Abhishek Tanwar

I build web & mobile experiences

  • HOME
  • BLOG
  • CONTACT ME
  • DISCLAIMER & COPYRIGHTS
You are here: Home / Building APIs / How to efficiently implement PRG and more in struts?

How to efficiently implement PRG and more in struts?

July 15, 2018 by Abhishek Tanwar

Hey there! If you have come here then you are looking for a solution on how to get long running struts action working faster and improve the user experience and have a proper flow.

With struts and actions we have below problems:

  1. Long running struts actions don’t have any way of handling. This should however not be a practice from start but some application functionalities require the same.
  2. User can submit again
  3. User can refresh page which trigers a resubmit again
  4. User needs to wait for the entire action to complete

There are ways to address all of above and improve user experience.

Apply PRG Pattern

This is first step towards enabling single submit approach. PRG stands for POST, REDIRECT and GET. The approach is when the form gets submitted, the struts action should redirect the output instead of forwarding and get enable a get to poll the status.

 

The PRG problem and solution is best explain by these wiki diagrams.

/wp-content/uploads/2018/07/PostRedirectGet_DoubleSubmitProblem.png
The Problem
PostRedirectGet_DoubleSubmitSolution
The Solution

This will disable resubmit if user refresh the page and anyway there is no submit button for user.

Now, this is straight foward. Below are configurations needed.

Enable redirection in struts-config.xml

Enable Redirection
Enable Redirection

Create a thread framework to handle the action

I will create a separate post for the same. Please watch this space for part 2.

Create Get API to Poll Request

This is pretty simple. Just a simple a simple jersey rest API to poll the status and show on the JSP page. This should be the forward of the redirection.

 

Disable Back and Submit

This is pretty tricky. There are many ways to disable BACK button of browser but unless you are create a new application this is not the best way. There are many things we can do to prevent/warn the user about the impact.

  1. Use body “onbeforeunload” to warn the user that BACK/REFRESH is going to have an impact on data.
  2. When the form is submitted, store a variable/token on the client side preferably in local storage to mark that the user has submitted the form. This can help to avoid resubmit by checking the value.
  3. Always include some timestamp in page urls to allow the client hit the server where validation can be done to ensure cache is not served. This can help to again ensure that proper data is submitted to struts action.

Part 2 coming soon where I describe the framework that I used to handle offline processing of struts actions.

Share this:

  • Facebook
  • X

Like this:

Like Loading...

Filed Under: Building APIs, Tips & Tricks Tagged With: PRG, struts long running actions, struts PRG, struts1 long running actions

Primary Sidebar

  • Behance
  • Email
  • Facebook
  • GitHub
  • LinkedIn

Popular Posts

How To Integrate React in JSP Application
SaaS, PaaS, IaaS
XQuery highlighting in Notepad++
Standard Design Patterns – Applied to JAVA
XQDT Installation on Eclipse JUNO

Categories

  • Building APIs
  • Building Mobile Apps
  • Building Web Apps
  • Coding Challenges
  • Extensions
  • Fullstack
  • Patterns
  • Tips & Tricks
  • Uncategorized
  • VSCode

Tags

2022 vscode extensions Abstract Factory alienware amazing vscode extensions apple challenges coding coding-challenges Design Patterns dota2 dota2 items dynamic web service call dynamic webservice invocation enterprise integration express flex helpful vscode extensions how to implement mfa in nodejs increasing productivity using vscode integration pattern macro message channel message endpoint message pattern message router message translator messaging mfa offline action processing offline actions in struts pipes and filters PRG in struts react Steam struts System Emulator threads in struts utilities vscode vscode customization vscode extensions vscode productivity extensions xquery xquery 1.0 xquery design principles

Recent Posts

  • 15+ VSCode Extensions To Improve Your Productivity
  • Productivity and Quality Extensions for ReactJS in VSCode..
  • My goto VSCode plugins for 2022…
  • How to enable MFA for your application in Node.JS?
  • Structuring Express Application – How I do it?

Categories

  • Building APIs (8)
  • Building Mobile Apps (1)
  • Building Web Apps (7)
  • Coding Challenges (3)
  • Extensions (1)
  • Fullstack (6)
  • Patterns (8)
  • Tips & Tricks (41)
  • Uncategorized (43)
  • VSCode (2)

Tags

2022 vscode extensions Abstract Factory alienware amazing vscode extensions apple challenges coding coding-challenges Design Patterns dota2 dota2 items dynamic web service call dynamic webservice invocation enterprise integration express flex helpful vscode extensions how to implement mfa in nodejs increasing productivity using vscode integration pattern macro message channel message endpoint message pattern message router message translator messaging mfa offline action processing offline actions in struts pipes and filters PRG in struts react Steam struts System Emulator threads in struts utilities vscode vscode customization vscode extensions vscode productivity extensions xquery xquery 1.0 xquery design principles

Archives

  • August 2023 (1)
  • March 2022 (1)
  • February 2022 (1)
  • November 2020 (1)
  • April 2020 (2)
  • May 2019 (1)
  • April 2019 (1)
  • March 2019 (1)
  • December 2018 (1)
  • July 2018 (4)
  • June 2018 (3)
  • March 2018 (1)
  • May 2016 (1)
  • December 2015 (1)
  • May 2015 (1)
  • April 2015 (2)
  • March 2015 (1)
  • December 2014 (2)
  • November 2014 (2)
  • October 2014 (1)
  • August 2014 (2)
  • July 2014 (1)
  • April 2014 (1)
  • March 2014 (1)
  • February 2014 (2)
  • January 2014 (1)
  • December 2013 (4)
  • November 2013 (4)
  • October 2013 (3)
  • September 2013 (4)
  • August 2013 (2)
  • July 2013 (5)
  • June 2013 (9)
  • May 2013 (6)
  • April 2013 (2)
  • March 2013 (2)
  • January 2013 (1)
  • November 2012 (2)
  • HOME
  • BLOG
  • CONTACT ME
  • DISCLAIMER & COPYRIGHTS

Copyright © 2025

%d