my dog learned polymorphism
The moose likes Struts and the fly likes Forward back to the same page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Forward back to the same page" Watch "Forward back to the same page" New topic

Forward back to the same page

Pavel Shakhovich

Joined: May 12, 2005
Posts: 3
I have a link that can change the language on every page of the website i'm developing. In the struts action I'd like to do the business logic and forward back to the same page. The problem is I can't specify the input page in the struts config file because I don't know the target page.

So how can I find out what the input page was. Is there any struts like way?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Try mapping.getInput() or mapping.getInputForward() (mapping being the variable name of the ActionMapping object passed as a parameter to the execute() method of your Action class). getInputForward() does require that you put an input parameter on your action definition, but I'm not sure if getInput() does or not.

I don't understand your reasoning for not being able to specify an input parameter on your action definition. You don't need to know what page is eventually going to be displayed, you just need to know what action class is going to be called.

Consultant, Sima Solutions
Pavel Shakhovich

Joined: May 12, 2005
Posts: 3
Thanks Merrill for the answer.

I'll try to explain it better.
I'd like to implement a link on the toolbar of my web application to switch the user's locale using Struts. But it's not I'm struggling with. I want to return to the page where request came from afterwards.
So how can I configure this, since I cannot configure this in the action mapping of struts-config.xml, because simply the request can be sent from any of my jsp's.
Returning a 'new ActionForward(mapping.getInput())' from the Action also does not help here, because for the same reason I cannot configure an 'input' in struts-config.xml.
Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
instead of relying on Struts to solve this, can you do this:

Maintain the 'current' page of the user as a session variable. that way, whenever the request to change the language is made, you only have to read the session variable to know which jsp called it and use mapping.findforward() to fwd the request to the right jsp?
Jason Menard

Joined: Nov 09, 2000
Posts: 6450

Welcome to JavaRanch. We don't have many rules here, but we do have a naming policy which we try to strictly enforce. Please re-read this document and edit your display name in order to comply. For example, your previous name - Pavel Shakhovich - was perfectly acceptable and in line with what we are looking for. Thanks in advance, and we look forward to seeing you around the Ranch.
Jeremy Hsu
Ranch Hand

Joined: Mar 28, 2005
Posts: 79
Hi, there is a struct tag. It might be what you want

Pavel Shakhovich

Joined: May 12, 2005
Posts: 3
Thanks everebody for help.
I've solved this problem by storing the previous page in a session. An in change language action I simply form a new ActionForward based on the previous page.
It looks like as the fragment of the code below.
1. In all my actions I use this code:

2. And in the change language action I use:
I agree. Here's the link:
subject: Forward back to the same page
It's not a secret anymore!