How do you read local information from a session?

The next bit of code sets the Locale from the lang parameter to the querystring.

<c:if test="${param['lang'] != null}">
    <fmt:setLocale value="${param['lang']}" scope="session"/>
</c:if>

      

How do I read this variable now?

I know him a little noobish.

I need a bit of conditional logic to display one language reference if the locale was not set in the session scope with fmt:setLocale

, and another if it was set to a specific locale.

thanks

+1


a source to share


3 answers


Try the following:



<c:if test="${pageContext.request.locale.language == 'en'}"> 
    <a href="link1">Link 1</a> 
</c:if> 
<c:if test="${pageContext.request.locale.language != 'en'}"> 
    <a href="link2">Link 2</a> 
</c:if> 

      

+4


a source


<c:choose>
    <c:when test="${sessionScope['javax.servlet.jsp.jstl.fmt.locale.session'] eq 'en_CY'}">
        a href="?lang=en_GB">English</a>
    </c:when>
    <c:otherwise>
        <a href="?lang=en_CY">Cymraeg</a>
    </c:otherwise>
</c:choose>

      

this works, but is there a better way to write?



<c:when test="${sessionScope['javax.servlet.jsp.jstl.fmt.locale.session'] eq 'en_CY'}">

      

+2


a source


<c:choose>
    <c:when test="${pageContext.response.locale eq 'en_CY'}">
        <a href="?lang=en_GB">English</a>
    </c:when>
    <c:otherwise>
        <a href="?lang=en_CY">Cymraeg</a>
    </c:otherwise>
</c:choose>

      

this only works on itslef page.

but since reading it from pageContext it won't work on other pages by reading it with sessionScope (where it is set with fmt:setLocale

).

How would I read it with sessionScope?

0


a source







All Articles