Struts2讲义25
5.6.2
非表单标签介绍
技术要点
本节代码具体介绍一些非表单标签的使用方式。
非表单标签使用。
非表单标签功能演示。
演示代码
使用actionError和actionMessage标签的JSP文件:
<!-----------------文件名:ErrorAndMessage.jsp-------------><%@taglib prefix="s" uri="/struts-tags"%>……… <h3 align="left"> actionerror标签使用范例 </h3> <p> <s:actionerror /> </p> <h3 align="left"> actionmessage标签使用范例 </h3> <p> <s:actionmessage /> </p>………
使用actionError和actionMessage标签的Action文件:
<!--------------文件名:ErrorAndMessageAction.java-------------->public class ErrorAndMessageAction extends ActionSupport{ public String execute() throws Exception{ //调用Struts2API,设置error和Message信息 addActionError("Action的错误信息"); addActionMessage("Action的消息信息"); return SUCCESS; }}
使用tree和treenode标签的JSP文件:
<!---------文件名:tree.jsp--------><%@taglib prefix="s" uri="/struts-tags"%>……… <head> <title>登录页面</title> <s:head theme="ajax"/> </head> <body> <h3 align="left"> tree和treenode标签使用范例 </h3> <p> <s:tree id="root" label="HTML" theme="ajax"> <s:treenode label="<b>html1</b>" id="html1" theme="ajax"> <s:treenode label="subhtml1"id="subhtml1" theme="ajax"></s:treenode> <s:treenode label="subhtml2"id="subhtml2" theme="ajax"></s:treenode> </s:treenode> <s:treenode label="<b>html2</b>"id="html2" theme="ajax"/> </s:tree> </p> </body>
使用actionError和actionMessage标签的效果图5.29。
http://dl.iteye.com/upload/attachment/155849/56121ba0-a165-385d-9c02-d41e2708046d.jpg
图5.29 actionError和actionMessage标签使用范例图
使用tree和treenode标签的效果图5.30。
http://dl.iteye.com/upload/attachment/155851/5b89c682-aa39-3c5d-8109-e34e87d4cd28.jpg
图5.30 tree和treenode标签标签使用范例图
代码解释
(1)在本示例中可知actionerror标签是输出Struts2的API方法getActionError()中的信息。而actionmessage标签则是输出Struts2的API方法getActionMessage()中的信息。这两个方法返回的信息都是一个字符串类型的变量。
由图5.29也可知道,这两个标签显示在页面上的内容就是在Action代码中封装进去的字符串内容。
(2)treenode和tree标签不但需要联合使用而且都是需要指定ajax主题才能实现树形结构功能。具体使用方式如JSP代码中所示。
(3)component标签功能主要是让开发者自定义自己的Struts2标签。在下一小节结合将着重说明。这里暂时先不给出示例。
页:
[1]