Java 在 JSP 中,如何使用 JSTL 检查请求中是否存在某些会话属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20597043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In JSP, how can i check, using JSTL, if certain session attribute exists in request?
提问by Vladimir
This is code in servlet:
这是servlet中的代码:
HttpSession session = request.getSession(true);
session.setAttribute("user", user);
I am forwarding request to JSP, where i want to check if there is session scoped user parameter attached.
我正在将请求转发到 JSP,我想在其中检查是否附加了会话范围的用户参数。
<c:if test="${??? - check if user is attached to request}">
/ /message
</c:if>
采纳答案by JB Nizet
<c:if test="${sessionScope.user != null}">
There is a user **attribute** in the session
</c:if>
回答by TheDude
I think you mean checking the session scope right?
我认为您的意思是检查会话范围对吗?
<c:if test="${!empty sessionScope.user}">
回答by Nidhish Krishnan
you can do that by using the following code
您可以使用以下代码来做到这一点
Setting session in Servlet
设置会话 Servlet
HttpSession session = request.getSession();
session.setAttribute("user", user);
Access session value by EL
in JSP
通过EL
in访问会话值JSP
<p>${sessionScope:user}</p>
Checking the session in JSP
using JSTL
正在JSP
使用中检查会话JSTL
<c:if test="${sessionScope:user != null}" >
session value present......
</c:if>