struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Graham" <dgraham1...@hotmail.com>
Subject Re: Session Values for Action.LOCALE_KEY Change
Date Wed, 11 Sep 2002 13:31:30 GMT
I was talking about struts not seeing the change to your browser's language 
setting.  Of course you can change the language in struts with the code 
you've given.  I don't know what's causing your problem but it is rather 
strange.

Dave

>Hi, Dave,
>
>First, thanks for taking the time to address this.  You can do what you 
>said you cannot do with struts.  I do it.  The code is simple enough.  It 
>is (where the page with this code returns a checkbox choice of nine 
>languages as the value of the "locale" parameter):
>
>/////////////////////////
><%
>String language = null;
>String localeValue = request.getParameter("locale");
>
>if(localeValue != null) {
>     language = localeValue.substring(0, 2);
>     response.setContentType("text/html;charset=utf-8");
>     Locale newLocale = new Locale(language);
>     session.setAttribute(Action.LOCALE_KEY, newLocale);
>}
>%>
><template:insert template="../template/template_work.jsp">
>   <template:put name="title" content="../title/language_title.jsp"/>
>   <template:put name="navigation" 
>content="../navigation/standard_navigation.jsp"/>
>   <template:put name="content" content="../content/language_content.jsp"/>
></template:insert>
>///////////////////////
>
>I appreciate the fact that you endorse, as I do, the standard struts 
>presentation tier patterns (Intercepting Filter, Front Controller, View 
>Helper, Composite View (used here), Service to Worker, and Dispatcher View) 
>so ably outlined in Core J2EE Patterns by Alur, Crupi, and Malks.  However, 
>there are times when the best practices are not possible do to other 
>constraints, and this is one of those times.  I actually have it working 
>fine now by running two sessions.  When the first session comes into 
>index.jsp (Tomcat 4.0.2) I forward to a language.jsp page (with the above 
>code).  This creates, or reasons I yet don't understand, a new session for 
>the page.  Then, when I navigate throughout the site, it stays at the 
>latter session id.  Any return to index.jsp returns to the first session 
>id.  I am not kidding here, as that wag from Miami Dave Whatshisname says!  
>But, a return to the other pages returns you back to the second session id. 
>  It really does, honest.  So, what I did what to copy the index.jsp page 
>functionality into another page called home.jsp, and a return to home now 
>looks like a return to index.jsp but is a return to home.jsp, and that has 
>the second session id.  Why, I don't know yet.  But, I do know it changes 
>my language and keeps it changed, unless I go back to index.jsp, which has 
>the initial language all along.  Weird, huh?  Do you have an explanation.  
>Whatever the explanation is, it is doing what I want it to do now.  Thanks 
>again.
>
>At 11:02 PM 9/10/2002 -0600, you wrote:
>>You can't start up your server, hit the page in one language, change the 
>>language setting in your browser, and hit the page again and expect it to 
>>change languages.  Struts sets the language in the session the first time 
>>you hit the site and not after that.  This may be causing your strange 
>>problems.
>>
>>Also, sometimes even after restarting tomcat my page wouldn't change 
>>languages so I think it reloaded my old session from disk or something.
>>Generally, I've found that stopping the server and then changing your 
>>language works but not always.
>>
>>I would not allow direct access to your index.jsp files.  Create an 
>>index.jsp that redirects to a struts action (through the controller) that 
>>forwards to index2.jsp (your real index page).  That way, you're going 
>>through the controller for every request and can do some common security 
>>or logging there.
>>
>>Dave
>>
>>
>>>From: micael <caraunltd@harbornet.com>
>>>Reply-To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
>>>To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
>>>Subject: Re: Session Values for Action.LOCALE_KEY Change
>>>Date: Tue, 10 Sep 2002 16:04:55 -0700
>>>
>>>The problem was that there were different sessions.  So, I solved my 
>>>problem temporarily by creating a home.jsp in the same session as the 
>>>other pages, which is a different session for reasons I don't yet 
>>>understand from index.jsp.  Additionally, if I set my browser for 
>>>Italian, now the index.jsp page always is in English, but when I go to 
>>>the other pages they pick up the default value.  What is going on here?   
>>>I do not send the index.jsp page to the controller.
>>>
>>>At 03:56 PM 9/10/2002 -0600, you wrote:
>>>>Do you directly link to the index.jsp or go through the controller 
>>>>servlet?
>>>>You say the locale in the session is different on index.jsp, verify that 
>>>>you're in the same session between pages.
>>>>
>>>>Hope that helps,
>>>>Dave
>>>>
>>>>
>>>>>From: micael <caraunltd@harbornet.com>
>>>>>Reply-To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
>>>>>To: struts-user@jakarta.apache.org
>>>>>Subject: Session Values for Action.LOCALE_KEY Change
>>>>>Date: Tue, 10 Sep 2002 14:13:28 -0700
>>>>>
>>>>>I set the session locale in a language.jsp page with:
>>>>>   session.setAttribute(Action.LOCALE_KEY, new Locale(language));
>>>>>where language is a return from a form parameter "locale" via:
>>>>>    String localeValue = request.getParameter("locale");
>>>>>    String language = localeValue.substring(0, 2);
>>>>>This works on all pages, except the index.jsp page.  I can set the 
>>>>>language variable to ko and the entire site will stay on Korean, but 
>>>>>when I go to the index.jsp page, it is back to English.  If I go from

>>>>>the index.jsp page back to the other pages, they stay in Korean.  I am

>>>>>very puzzled.
>>>>>
>>>>>Any ideas.  I posted this before, but it chopped my code off.
>>>>>
>>>>>
>>>>>
>>>>>--
>>>>>To unsubscribe, e-mail:
>>>>><mailto:struts-user-unsubscribe@jakarta.apache.org>
>>>>>For additional commands, e-mail: 
>>>>><mailto:struts-user-help@jakarta.apache.org>
>>>>
>>>>
>>>>
>>>>
>>>>_________________________________________________________________
>>>>MSN Photos is the easiest way to share and print your photos: 
>>>>http://photos.msn.com/support/worldwide.aspx
>>>>
>>>>
>>>>--
>>>>To unsubscribe, e-mail:
>>>><mailto:struts-user-unsubscribe@jakarta.apache.org>
>>>>For additional commands, e-mail: 
>>>><mailto:struts-user-help@jakarta.apache.org>
>>>
>>>
>>>
>>>--
>>>To unsubscribe, e-mail:
>>><mailto:struts-user-unsubscribe@jakarta.apache.org>
>>>For additional commands, e-mail: 
>>><mailto:struts-user-help@jakarta.apache.org>
>>
>>
>>
>>
>>_________________________________________________________________
>>Chat with friends online, try MSN Messenger: http://messenger.msn.com
>>
>>
>>--
>>To unsubscribe, e-mail:   
>><mailto:struts-user-unsubscribe@jakarta.apache.org>
>>For additional commands, e-mail: 
>><mailto:struts-user-help@jakarta.apache.org>
>>
>
>
>
>--
>To unsubscribe, e-mail:   
><mailto:struts-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: 
><mailto:struts-user-help@jakarta.apache.org>




_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


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


Mime
View raw message