File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Visiting two pages for one action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Visiting two pages for one action" Watch "Visiting two pages for one action" New topic
Author

Visiting two pages for one action

Greg Werner
Ranch Hand

Joined: May 07, 2009
Posts: 54
Hello all.

This seems to me to be possible but maybe not. I need to visit 2 pages in one action. I can not simply chain actions I do not think because the first page I visit is in another web application. So here is my scenario. I perform an action, then some task is performed in another application by visiting a JSP/Servlet , then control is returned back to the user on some predetermined page in the original application. I need to communicate on port 80 with that application and have though about Hessian or HttpInvoke, but I want to see with just Struts it is possible to accomplish.
Tom Hollins
Greenhorn

Joined: Mar 06, 2010
Posts: 9
I am doing this in order to have the user go to PayPal and then back into my App. Your need is the same as mine:
1) User initiates an action in their browser on a web page you served.
2) That action takes them to someone else's web site.
3) In my case, when PayPal is done with the user, there is a web page that PayPal will request. I have entered that URL when setting up the business side of PayPal.

This is all configured through the file named struts.xml in src/main/resources/ (at least the way I am setup).

This shows an example of chaining one page to another with a break between one page and the next due to "some other site" calling that next page (which is the ppnotify action).
signup.jsp ---> paypal.jsp ---> The Real PayPal Site ---> ppnotify.jsp ---> mainmenu.jsp
That would be the sequence.

What the <paypal> action is saying to struts is "there is no action to take once the page is rendered". This is because there is no result defined.

Hope this helps as well as answers your question.
-T-
Joroto.com
Greg Werner
Ranch Hand

Joined: May 07, 2009
Posts: 54

This shows an example of chaining one page to another with a break between one page and the next due to "some other site" calling that next page (which is the ppnotify action).
signup.jsp ---> paypal.jsp ---> The Real PayPal Site ---> ppnotify.jsp ---> mainmenu.jsp
That would be the sequence.


Actually what I am looking for is sort of an asynchronous piece. I want to sort of spawn something in the second application and continue assuming that it will behave correctly and not needing the results. If the second application does not handle it correctly, oh well, the second application will have to live with it. So from paypal.jsp, I would want two different actions to fire, with the page I end up on being mainmenu.jsp from the calling application and not getting stuck in the second application which will give no reponse of any kind back to the calling application.

So I am looking for:

signup.jsp ---> paypal.jsp -----> External App
....................................|
....................................|
....................................\------> mainmenu.jsp
Tom Hollins
Greenhorn

Joined: Mar 06, 2010
Posts: 9
I still have questions. Does the paypal.jsp need to do some processing before calling the off-site page? If not then you should just use javascript to open it in a new window/tab.
If you have to call it after the processing of the paypal.jsp submit then, again I'm in paypal mode so here is how you do it just before returning the result to your action. This is directly from PayPal's jsp example.

The pw.println(str) is just sending the variables to the paypal page. Its not a requirement if there are no get/post variables to send. You've done this in Java so that external site gets hit.

As far as the original question, "I don't know" how to do it in the struts.xml in the actions. I believe that since one is working in a tree model that is single threaded, then one would need to put the fork of the action inside the browser where you have control that can start up a new session in a new window/tab. I don't think it can be done.

If you write an interceptor then the interceptor will fork (as in the above Java code).

Cheers,
-T-
Joroto.com
Greg Werner
Ranch Hand

Joined: May 07, 2009
Posts: 54
Tom Hollins wrote:



Yeah, bulls-eye! I was looking for some magic beans. That really does appear the only way to go. Sometimes when I use these high level frameworks, I think it dirty to use java.net and such. Thanks for sticking with me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Visiting two pages for one action