开发者

How to get dynamically session object in struts2

开发者 https://www.devze.com 2023-02-02 03:22 出处:网络
I am trying to get dynamically session object in struts2 application. <s:if test=\"%{#session[\'resToken\'].bookingType == 1}\">

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 


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


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}.


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


'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.


I have gotten its solution ..

first is set resToken

check setTest Test 11 Test 11

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号