Struts标签中session判断jsp模块

 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 <%@ taglib prefix="s" uri="/struts-tags"%>
 3 
 4 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 5 <html>
 6     <head>
 7         <title>My JSP 'login.jsp' starting page</title>
 8 
 9         <meta http-equiv="pragma" content="no-cache">
10         <meta http-equiv="cache-control" content="no-cache">
11         <meta http-equiv="expires" content="0">
12 
13     </head>
14 
15     <body>
16     <s:if test="#session.username==null">
17         <s:text name="struts.myssh.login"/>
18         <hr>
19         <s:form action="Login" method="post">
20             ${log_err}
21             <s:textfield name="username" key="struts.myssh.name" size="20" />
22             <s:password name="password" key="struts.myssh.password" size="20" />
23             <s:submit key="struts.myssh.login" />
24         </s:form>
25         </s:if>
26         <s:else>
27             ${session.username}
28         </s:else>
29     </body>
30 </html>

通过<s:if></if>标签判断session.username(用户名)是否存在,如果存在显示标签内的模块内容,如果不存在,显示<s:else></s:else>标签内的模块内容。

posted @ 2012-11-28 11:30  hlb  阅读(330)  评论(0编辑  收藏  举报