【struts標(biāo)簽】
bean:define
定義變量賦值有三種方式:
1。設(shè)置value屬性,此時id屬性定義的變量為字符串,value屬性代表這個變量的字符串值。
?<bean:defind id="userName" value="jing" />
?UserName: <bean:write name="userName"/>
2。同時設(shè)置name和property屬性。name屬性指定一個已經(jīng)存在的Bean。
Property屬性指定已經(jīng)存在的Bean的某個屬性。id屬性定義的變量的值由property屬性決定。
? <%request.setAttribute("sessionBean",session);%>
?<bean:defind id="theSession" name="sessionBean" property="servletContext"/>
?ServletContext Name: <bean:write name="theSession" property="servletContextName"/>
3。同時設(shè)置name和type屬性。
<bean:defind id="loginBean" name="loginBean" type="com.jason.action.LoginBean"/>
<bean:write name="loginBean" property="password"/>
bean:size
用于獲得Map,Collection的長度,id指定一個Integer類型的變量,name指定已經(jīng)存在的map,collection或者數(shù)組。
<%
HashMap lines = new HashMap();
lines.put("1","Line 1");
lines.put("2","Line 2");
lines.put("3","Line 3");
request.setAttribute("lines",lines);
%>
<bean:size id="length" name="lines"/>
<bean:write name="length"/>