自定义 JSP 页面
根据用户会话,我必须在 JSP 上显示不同的内容。
有问题请指教
<c:if test="${session.getAttribute("userEmail")}">
<c:choose>
<c:when test="[email protected]"> //here if test is not null
<tr>
<td colspan="1" width="40%" nowrap="nowrap" style="text-align: left;">
<img src="<%=request.getContextPath()%>/images/icons/chevron_double.gif"/>
<a href="http://www.google.com" class="underlinedLinksLic">Google</a>
<img src="<%=request.getContextPath()%>/images/icons/chevron_double.gif"/>
<a href="http://www.gmail.com" class="underlinedLinksLic">Gmail</a></td>
</tr>
</c:when>
<c:when test="[email protected]"> //here if session is null
<tr>Hello</tr>
</c:when>
<tr height="3px;">
<td> </td>
</tr>
</c:choose>
Based on the user session I have to display different stuff on JSP.
Something is wrong, please advice
<c:if test="${session.getAttribute("userEmail")}">
<c:choose>
<c:when test="[email protected]"> //here if test is not null
<tr>
<td colspan="1" width="40%" nowrap="nowrap" style="text-align: left;">
<img src="<%=request.getContextPath()%>/images/icons/chevron_double.gif"/>
<a href="http://www.google.com" class="underlinedLinksLic">Google</a>
<img src="<%=request.getContextPath()%>/images/icons/chevron_double.gif"/>
<a href="http://www.gmail.com" class="underlinedLinksLic">Gmail</a></td>
</tr>
</c:when>
<c:when test="[email protected]"> //here if session is null
<tr>Hello</tr>
</c:when>
<tr height="3px;">
<td> </td>
</tr>
</c:choose>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是行不通的。这应该是
只要作用域属性
userEmail
不是null
或空字符串,就会输入
块。要在userEmail
属性为null
或空字符串时显示一些内容,请执行以下操作:此外,这些字符串比较
应该已经
了解了这些事实,您应该能够重构您的
和
块更合适。下面是一个示例:另请参阅:
This ain't going to work. This should have been
The
<c:if>
block will then be entered whenever the scoped attributeuserEmail
is notnull
or empty string. To show some stuff when theuserEmail
attribute isnull
or empty string, then do so:Further, those String comparisons
should have been
Knowing those facts, you should be able to reconstruct your
<c:if>
and<c:choose>
blocks more appropriately. Here's an example:See also:
尝试使用会话对象(取决于您如何在用户登录的会话中标记):
Try to use session object (depends on how you mark in session that user logged in):