aspose file tools*
The moose likes Struts and the fly likes Page refresh after Action execute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Page refresh after Action execute" Watch "Page refresh after Action execute" New topic
Author

Page refresh after Action execute

Srinivas Nagesh
Greenhorn

Joined: Oct 27, 2002
Posts: 19
Hi,

I am currently working on a small web app and this is the first time i am using struts. Here is what i am trying to achieve

A JSP page on form post, calls a struts action. Once this action completes it task, I need to return to the calling JSP and refresh it repeatedly to poll for the results of this task. Please note that all my action does is to execute a java Executor.

I have this configured by specifying the calling page in the result attribute of the action definition in the struts.xml. The problem is that when the action completes its execution and returns to jsp, the url after the return is http://localhost:8080/mywebapp/dosomething.action. Now since i defined a meta tag for the page to refresh, the action is submitted everytime the page refreshes. I think its not refreshing the jsp, but its refreshing the url.

As a workaround, i have defined the result to a temporary page from which i am redirecting to this caller jsp. I am not liking this hack and would like to understand how should this problem be correctly implemented.

Really appriciate any help on this

Thanks in advance
Srinivas Nagesh
Greenhorn

Joined: Oct 27, 2002
Posts: 19
bump
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

After you reach the JSP page, you want to request for that JSP page again and again. You don't need to go through the Action to reach to the JSP. That means that the JSP doesn't actually need anything from the action and works on its own. Is this right??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Srinivas Nagesh
Greenhorn

Joined: Oct 27, 2002
Posts: 19
The JSP needs info from the action and also need to submit the form post to the action

This is use case. Hope it helps

1. User logs into the app and reaches test.jsp (http://.../test.jsp)
2. User submits a form post which submits to test.action
3. test action class perform some operation in a background thread
4. A "success" result should return to test.jsp
5. A "error" result should return to test.jsp with a message which I am accessing via struts2 property tag to display on test.jsp
6. The test.jsp refreshes to poll for the result of the operation from teststatusManager

The issue is that when the call returns to the jsp, the url in the browser is http://.../test.action. Due to this when the jsp refreshes to poll for the result of the operation performed from the teststatusManager, it re-submits test.action which is not the intention of the refresh.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

So at step 6, you want test.jsp to poll to teststatusManager.action?? This is easy to do, you can use the meta tag to achieve this (as I think you already did in an intermediate page that you used). You just need to use a syntax like given here i.e.
Srinivas Nagesh
Greenhorn

Joined: Oct 27, 2002
Posts: 19
Ankit,

I got your point. I split the action to submit and the action to refresh into 2. That resolved my problem. Thanks for your inputs.

Thanks,
Srinivas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Page refresh after Action execute
 
Similar Threads
Calling an action class at regular intervals
Struts2 Action Not forwarding to a result
ExecAndWait interceptor parameters lost
Problem refreshing page
Refreshing a page causes a duplicate row to be inserted pls help...????