Struts学习笔记: Bean标签库学习

2008-02-23 07:54:56来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

Bean标签库

1. <bean:header> #0968F7

<bean:header id="custlang" name="Accept-Language"/>
Here: <bean:write name="custlang"/>
=>
Here: zh-cn,en-us;q=0.5

2. <bean:parameter>

<bean:parameter id="bookId" name="id" value="0"/><%--value是默认值-%>
请求的图书编号为: <bean:write name="bookId"/>
=>
请求的图书编号为: 8 <!-- http://localhost/AddressBook/MyJsp.jsp?id=8-->

<bean:parameter id="custNames" multiple="true" name="names" value="hehe"/>
请求的客户姓名有: <p/>
<%
for( int i = 0 ; i < custNames.length; i ) {
out.print(custNames[i] "__");
}
%>
=>
请求的客户姓名有: <p/>
cheyo__vsftpd__Google__

3. <bean:cookie>

Cookies: <bean:cookie id="customer" name="custName" value="cheyo"/>
您好,<bean:write name="customer" property="value"/>
=>
Cookies:
您好,cheyo

4. <bean:page>

<bean:page id="currSession" property="session"/>
当前会话创建时间: <bean:write name="currSession" property="creationTime"/>
=>
当前会话创建时间: 1111993122390

5. <bean:message>

<1>
<bean:message bundle="test" key="test.name"/><p/>
<2>
<%
request.setAttribute("stringBean", "test.nick");
%>
<bean:message bundle="test" name="stringBean"/>
<3>
<%
SomeBean bean = new SomeBean();
bean.setName("hello");
request.setAttribute("someBean", bean);
%>
<bean:message bundle="test" name="someBean" property="name"/>
<4>
<bean:message bundle="test" key="test.error" arg0="联系地址!"/>
<!--test.error={0} is requried!-->

6. <bean:resource>

以下为test页面的内容:<p/>
<bean:resource id="testPage" name="test/testDS.jsp"/>
<bean:write name="testPage"/>

7. <bean:struts>

<bean:struts id="successForward" forward="aaaa"/>
<bean:write name="successForward" property="path"/>
=>
/hello.jsp

8. <bean:include>

以下为include进的内容:<p/>
<bean:include id="includeReg" forward="success"/>
<bean:write name="includeReg" filter="false" />
<p/>

以下为include进的内容3:<p/>
<bean:include id="includeReg" page="/hello.jsp"/><%--一定要以/开头--%>
<bean:write name="includeReg" filter="false" />

9. <bean:define>

<1>
<bean:define id="currDate" value="2005-03-28"/>
<bean:write name="currDate"/>
<2>
<%
User user = new User();
user.setUserName("cheyo");
request.setAttribute("userBean", user);
%>
<bean:define id="currUser" name="userBean"/>
当前用户姓名: <bean:write name="currUser" property="userName"/>
<%-- 注意: 上面加下划线的"user"这一变量名不应与红色下划线的"currUser"这一变量名相同! 否则会报错! -->

10. <bean:size>

<%
HashMap lines = new HashMap();
lines.put("1", "line1");
lines.put("2", "line2");
lines.put("3", "line3");
request.setAttribute("lines", lines);
%>
<bean:size id="lineSize" name="lines"/>
线的数量:
<bean:write name="lineSize"/>

11. <bean:write>

<1>

<%
request.setAttribute("floatval", Float.valueOf("3.14159"));
Calendar gc = GregorianCalendar.getInstance();
gc.setTime(new Date(session.getCreationTime()));
request.setAttribute("now", gc);
%>
Pi is : <bean:write format="#.####" name="floatval"/><p/>
Session Started at: <bean:write format="MM-dd-yyyy hh:mm:ss" name="now" property="time"/>

<2>

<%
String boldStart = "<B>";
String boldEnd = "</B>";
request.setAttribute("bs", boldStart);
request.setAttribute("be", boldEnd);
%>
<bean:write name="bs"/>哈哈哈哈<bean:write name="be"/><p/> <%--输出<B>哈哈哈哈</B>--%>
<bean:write name="bs" filter="false"/>加粗的哈哈哈哈<bean:write name="be" filter="false"/><p/>

=>
&lt;B&gt;哈哈哈哈&lt;/B&gt;<p/>
<B>加粗的哈哈哈哈</B><p/>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Struts学习笔记: Html标签库学习(Html基本标签)

下一篇:配置定时运行的Servlet