You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thomas Hamacher <th...@qualigo.de> on 2006/08/24 14:49:18 UTC

Forward to the same page

Hello everyone,

I´m returning to a problem I already had, but after googling for a while I 
could not find a good solution to that. So I´d like to ask you again, hoping 
that someone has a solution and I simply overlooked something.

How do I forward to the same page I was coming from? The typical example for 
this is the "change-language-problem". Someone is on one page and simply 
wants to change the language and expects to see the same page in a different 
language.
Another case could be, that I put a login-form on every page and no matter 
when the login is performed, the user will be returned to the same page he 
has been before.
Unfortunately I could not get this thing to work. As I´m using tiles most of 
the common forwards do not really work, as I can´t simply redirect to a 
JSP-Page on my server. I found another solution where people stored their 
last ActionForward into the session and recall this ActionForward. But this 
is only working if a user has only one browser-tab or one browser-window. If 
he works with more than one, he won´t get the page he expects, but the page 
where he has been with the other browser-window. So this could not be "the" 
solution as well.
Using the mapping.getInput() doesn´t work either as 1. I hava a dynamic input 
value and 2. it might be that a ForwardAction has been used, so the 
getInput() is null.

I can´t believe that this is such an uncommon problem. Could someone please 
help me out and point me to a place where to find a solution?

Thank you very much

Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


[OT] Re: Forward to the same page

Posted by Antonio Petrelli <br...@tariffenet.it>.
Manfred Wolff ha scritto:
> hi antonio,
>   

It wasn't me that asked the question, thank you anyway :-)

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Forward to the same page

Posted by Manfred Wolff <wo...@manfred-wolff.de>.
hi antonio,


Try http://www.manfred-wolff.de/struts/articles/HowTo-Back.html. In this
solution you can go back and stay where you are for language switching.

Manfred

Struts goes mobile. See http://www.strutsme.org



leo mj wrote:
> hi antonio,
>
>
>  It can be done by using ActionForwards.Also go tru internatinalization in struts
> for displaying langauage :
> http://www.allapplabs.com/struts/struts_internationalization.htm
>
>
> in the action class use
>   ActionForward forward=new ActionForward();
>
> if(chk whther the language  combo box has been selected ){
>
>   forward=mapping.getInputForward();
>
> }
>
> add internationalization code using 
> <bean:messageKey>
> get language to be selected using request.getAttribute("fieldName");
>
> in ur jsp...
>
> Regards,
> Leo
>
>
>
>
>
>
>
>   
>
> Artem Zhmurov <da...@yandex.ru> wrote: What about using JavaScript? Try this:
>
>
>
>
>  
> Changing location 
>
>
>
>  
> function changeLanguage(lang){
>  var location = window.location.href;
>  if(location.indexOf("?") == -1){
>   location += "?lang=";
>   location += lang;
>   window.location = location;
>  } else {
>   var pos = location.indexOf("lang=");
>   if(pos != -1){
>    var new_location = location.substring(0, pos + 5);
>    new_location += lang;
>    window.location = new_location;
>   } else {
>    location += "&lang=";
>    location += lang;
>    window.location = location;
>   }
>  }
> }
>
>
>
>  [input]  
>  [input]  
>
>
>
> It will work if you don't need the addition page (such as when dealing with
> login).
>
> Also you have to be sure, that your lang=.. parameter is in the end of
> parameters line (that is true until you're not trying to add lang=..
> somewhere outside). And there will be problem if your application dealing
> with parameters named, for example, 'XXXlang'. All imperfections mentioned
> can be removed by some little changes in script.
>
>   
>> -----Original Message-----
>> From: Antonio Petrelli [mailto:brenmcguire@tariffenet.it]
>> Sent: Friday, August 25, 2006 12:09 PM
>> To: Struts Users Mailing List
>> Subject: Re: Forward to the same page
>>
>> Thomas Hamacher ha scritto:
>>     
>>> How do I forward to the same page I was coming from? The typical example
>>>       
>> for
>>     
>>> this is the "change-language-problem". Someone is on one page and simply
>>> wants to change the language and expects to see the same page in a
>>>       
>> different
>>     
>>> language.
>>>
>>>       
>> Just an idea,  tag has the "action" attribute that is no more
>> required. If it is not specified the last servlet path (i.e. "post
>> back") will be taken.
>> http://struts.apache.org/1.x/struts-taglib/tlddoc/html/form.html
>> You could grab the code that controls the value of the "action"
>> attribute to determine the path you're coming from. Then you "change the
>> language" and then redirect (I think it's better than forwarding) to the
>> previous servlet path.
>>
>> HTH
>> Antonio
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>     
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>  		
> ---------------------------------
> How low will we go? Check out Yahoo! Messenger’s low  PC-to-Phone call rates.
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Forward to the same page

Posted by leo mj <le...@yahoo.com>.
hi antonio,


 It can be done by using ActionForwards.Also go tru internatinalization in struts
for displaying langauage :
http://www.allapplabs.com/struts/struts_internationalization.htm


in the action class use
  ActionForward forward=new ActionForward();

if(chk whther the language  combo box has been selected ){

  forward=mapping.getInputForward();

}

add internationalization code using 
<bean:messageKey>
get language to be selected using request.getAttribute("fieldName");

in ur jsp...

Regards,
Leo







  

Artem Zhmurov <da...@yandex.ru> wrote: What about using JavaScript? Try this:




 
Changing location 



 
function changeLanguage(lang){
 var location = window.location.href;
 if(location.indexOf("?") == -1){
  location += "?lang=";
  location += lang;
  window.location = location;
 } else {
  var pos = location.indexOf("lang=");
  if(pos != -1){
   var new_location = location.substring(0, pos + 5);
   new_location += lang;
   window.location = new_location;
  } else {
   location += "&lang=";
   location += lang;
   window.location = location;
  }
 }
}



 [input]  
 [input]  



It will work if you don't need the addition page (such as when dealing with
login).

Also you have to be sure, that your lang=.. parameter is in the end of
parameters line (that is true until you're not trying to add lang=..
somewhere outside). And there will be problem if your application dealing
with parameters named, for example, 'XXXlang'. All imperfections mentioned
can be removed by some little changes in script.

> -----Original Message-----
> From: Antonio Petrelli [mailto:brenmcguire@tariffenet.it]
> Sent: Friday, August 25, 2006 12:09 PM
> To: Struts Users Mailing List
> Subject: Re: Forward to the same page
> 
> Thomas Hamacher ha scritto:
> > How do I forward to the same page I was coming from? The typical example
> for
> > this is the "change-language-problem". Someone is on one page and simply
> > wants to change the language and expects to see the same page in a
> different
> > language.
> >
> 
> Just an idea,  tag has the "action" attribute that is no more
> required. If it is not specified the last servlet path (i.e. "post
> back") will be taken.
> http://struts.apache.org/1.x/struts-taglib/tlddoc/html/form.html
> You could grab the code that controls the value of the "action"
> attribute to determine the path you're coming from. Then you "change the
> language" and then redirect (I think it's better than forwarding) to the
> previous servlet path.
> 
> HTH
> Antonio
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



 		
---------------------------------
How low will we go? Check out Yahoo! Messenger’s low  PC-to-Phone call rates.

RE: Forward to the same page

Posted by Artem Zhmurov <da...@yandex.ru>.
What about using JavaScript? Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Changing location</title>
</head>
<body>
<script language="JavaScript">
	
function changeLanguage(lang){
	var location = window.location.href;
	if(location.indexOf("?") == -1){
		location += "?lang=";
		location += lang;
		window.location = location;
	} else {
		var pos = location.indexOf("lang=");
		if(pos != -1){
			var new_location = location.substring(0, pos + 5);
			new_location += lang;
			window.location = new_location;
		} else {
			location += "&lang=";
			location += lang;
			window.location = location;
		}
	}
}

</script>

<input type="button" value="RUS" onclick="changeLanguage('ru')"/> 
<input type="button" value="ENG" onclick="changeLanguage('en')"/> 
</body>
</html>

It will work if you don't need the addition page (such as when dealing with
login).

Also you have to be sure, that your lang=.. parameter is in the end of
parameters line (that is true until you're not trying to add lang=..
somewhere outside). And there will be problem if your application dealing
with parameters named, for example, 'XXXlang'. All imperfections mentioned
can be removed by some little changes in script.

> -----Original Message-----
> From: Antonio Petrelli [mailto:brenmcguire@tariffenet.it]
> Sent: Friday, August 25, 2006 12:09 PM
> To: Struts Users Mailing List
> Subject: Re: Forward to the same page
> 
> Thomas Hamacher ha scritto:
> > How do I forward to the same page I was coming from? The typical example
> for
> > this is the "change-language-problem". Someone is on one page and simply
> > wants to change the language and expects to see the same page in a
> different
> > language.
> >
> 
> Just an idea, <html:form> tag has the "action" attribute that is no more
> required. If it is not specified the last servlet path (i.e. "post
> back") will be taken.
> http://struts.apache.org/1.x/struts-taglib/tlddoc/html/form.html
> You could grab the code that controls the value of the "action"
> attribute to determine the path you're coming from. Then you "change the
> language" and then redirect (I think it's better than forwarding) to the
> previous servlet path.
> 
> HTH
> Antonio
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Forward to the same page

Posted by Antonio Petrelli <br...@tariffenet.it>.
Thomas Hamacher ha scritto:
> How do I forward to the same page I was coming from? The typical example for 
> this is the "change-language-problem". Someone is on one page and simply 
> wants to change the language and expects to see the same page in a different 
> language.
>   

Just an idea, <html:form> tag has the "action" attribute that is no more 
required. If it is not specified the last servlet path (i.e. "post 
back") will be taken.
http://struts.apache.org/1.x/struts-taglib/tlddoc/html/form.html
You could grab the code that controls the value of the "action" 
attribute to determine the path you're coming from. Then you "change the 
language" and then redirect (I think it's better than forwarding) to the 
previous servlet path.

HTH
Antonio


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org