struts2中如何动态获取session对象
我正在尝试在 struts2 应用程序中动态获取会话对象。
<s:if test="%{#session['resToken'].bookingType == 1}">
resToken 可以通过
获取
,但我不能写
内
它给了我双引号错误..
org.apache.jasper.JasperException: /WEB-INF/jsp/booking/banquet/guest-Info-View.jsp(150,40) Unterminated <s:if tag
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 <s:if tag
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你不能使用
${sessionScope.resToken.bookingType == 1}
Can't you use
${sessionScope.resToken.bookingType == 1}
如果我没看错的话,那么
resToken
的值实际上是会话属性的名称,对吧?因此,请尝试类似:${sessionScope[resToken].bookingType}
。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}
.尝试将
标记放在
标记内并不是正确的方法。这两个标签都采用 OGNL 表达式作为参数。因此,如果%{resToken}
适用于其中一个,那么它也应该适用于另一个。话虽如此,
%{#session['resToken'].bookingType}
看起来是正确的。您是否尝试过输出它的值来看看它是什么?您还可以使用%{#session.resToken.bookingType}
。首先确定您是否正确引用了会话变量,然后确保该值确实==
1。或者您可以像其他人建议的那样使用 JSTL/JSP EL 并使用:
OGNL 参考
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:
OGNL Reference
'resToken' 不等于 resToken,后者是一个变量,您似乎希望第一个是字符串。
简单地写:
如果这不起作用,请使用属性标签输出表达式的较小部分以查看返回的内容。
'resToken' is not equal to resToken, the later is a variable which you seem to want the first is a string.
Simply write:
If this does not work please use property tags to output smaller parts of the expression to see what is returned.
我已经得到了它的解决方案..
首先是设置 resToken
检查 setTest
测试 11 测试 11
I have gotten its solution ..
first is set resToken
check setTest
Test 11 Test 11