Sujeet Singh
Sujeet Singh

Reputation: 1

How to get dynamically session object in struts2

I am trying to get dynamically session object in struts2 application.

<s:if test="%{#session['resToken'].bookingType == 1}">

resToken can be get by <s:property value="%{resToken}">..

But I can't write <s:property> within <s:if test="">

its giving me error of double quotes..

org.apache.jasper.JasperException: /WEB-INF/jsp/booking/banquet/guest-Info-View.jsp(150,40) Unterminated &lt;s:if tag 

Upvotes: 0

Views: 5875

Answers (5)

Sujeet Singh
Sujeet Singh

Reputation: 1

I have gotten its solution ..

first is set resToken

check setTest Test 11 Test 11

Upvotes: 0

Quaternion
Quaternion

Reputation: 10458

'resToken' is not equal to resToken, the later is a variable which you seem to want the first is a string.

Simply write:

<s:if test="%{#session[resToken].bookingType == 1}">

If this does not work please use property tags to output smaller parts of the expression to see what is returned.

Upvotes: 0

Steven Benitez
Steven Benitez

Reputation: 11055

Trying to put an <s:property/> tag inside of an <s:if/> tag isn't the right approach. Both tags take an OGNL expression as their argument. Therefore, if %{resToken} is working for one, it should work for the other too.

With that said, %{#session['resToken'].bookingType} looks correct. Have you tried outputting the value of that to see what it is? You can also use %{#session.resToken.bookingType}. First determine that you are properly referencing the session variable, then make sure that the value really does == 1.

Or you can use JSTL/JSP EL like the others suggested and go with:

// i don't remember off the top of my head if it should be == or eq
<c:if test="${sessionScope.resToken.bookingType eq 1}"></c:if>

OGNL Reference

Upvotes: 1

kschneid
kschneid

Reputation: 5694

If I'm reading that right, then the value of resToken is actually the name of a session attribute, right? So, try something like: ${sessionScope[resToken].bookingType}.

Upvotes: 1

Bozho
Bozho

Reputation: 597422

Can't you use ${sessionScope.resToken.bookingType == 1}

Upvotes: 1

Related Questions