1

I have the language code in java variable. I want to set that code into setLocale value like

<%

String lang="en";

%>
<fmt:setLocale value="${lang}" scope="session"/>

But this was not working correctly. But when i set like

<fmt:setLocale value="en" scope="session"/> ,it was working perfectly. The language may be es,de... So i want to set the value like <fmt:setLocale value="${lang}" scope="session"/>.

Is any solutions? Please help me.

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
Bala
  • 11
  • 1
  • 2

2 Answers2

0

As mentioned in comment use set tag

 <c:set var="language" value="${not empty param.language ?
          param.language : not empty language  ? language :
                        pageContext.request.locale}" scope="session" />
                                           <fmt:setLocale value="${language}" />

See here for full description How to internationalize a Java web application?

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • This was not change the language for the entire session. Some pages only get change. – Bala Apr 18 '13 at 06:26
  • I have 18 jsp pages.I have included the setLocale code in all tha pages. When i use like value="en" , it works fine. But i cant set the value dynamically. – Bala Apr 18 '13 at 06:45
  • Are you setting the value value="${not empty param.language ? param.language : not empty language ? language : pageContext.request.locale}. – Suresh Atta Apr 18 '13 at 06:47
0

Try it this way:

<fmt:setLocale value="<%=lang%>" scope="session"/>
skuntsel
  • 11,624
  • 11
  • 44
  • 67