1 / 20

第六讲 Struts 标签(一)

第六讲 Struts 标签(一). 博和利初级培训 — 开发技能. Struts 标记. JSP 视窗组件所使用的 struts 标记库由四类标记组成: Bean 标记:用来在 JSP 页中管理 bean 逻辑标记:用来在 JSP 页中控制流程  HTML 标记:用来生成 HTML 标记,在表单中显示数据,使用 会话 ID 对 URL 进行编程 模板标记:使用动态模板构造普通格式的页. 定制 JSP 标记. Struts-bean.tld 使访问 bean 以及新 bean 的定义更容易,为了实现国际化,应使用不同的属性文件 struts-html.tld

Download Presentation

第六讲 Struts 标签(一)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第六讲 Struts标签(一) 博和利初级培训—开发技能

  2. Struts标记 JSP视窗组件所使用的 struts标记库由四类标记组成: • Bean标记:用来在JSP页中管理bean • 逻辑标记:用来在JSP页中控制流程 • HTML标记:用来生成HTML标记,在表单中显示数据,使用 会话ID对URL进行编程 • 模板标记:使用动态模板构造普通格式的页

  3. 定制JSP标记 • Struts-bean.tld 使访问bean以及新bean的定义更容易,为了实现国际化,应使用不同的属性文件 • struts-html.tld 提供显示HTML对象(例如,表单、按钮和复选框)的简便方法 • struts-logic.tld 支持逻辑构造,以便可以有条件地显示文本或者作为处理循环的结果来显示文本 • struts-template.tl 支持使用在运行时可以修改的JSP模板

  4. Bean标记 这个标记库中包含用于定义新bean、访问bean及其属性的标记。 • 创建和复制bean的标记 •  脚本变量定义标记 •  bean翻译标记 •  消息国际化标记

  5. Bean复制标记 • 例如:定义一个bean: <bean:define id=”test” value=”this is a test”/> • 源bean在页作用域中被拷贝大哦请求作用域中的另一个bean: <bean:define id=”targetBean” name=”sourceBean” scope=”page” toScope=”request”/>

  6. 定义脚本变量的标记 • <bean:cookie id=”myCookie” name=”userName”/> 脚本变量名称是myCookie,用来创建这个属性的cookie的名称是userName。 • <bean:header id=”myHeader” name=”Accept-Language”/> 脚本变量名称是myHeader,请求标头的名称是Accept-Language. • <bean:parameter id=”myParameter” name=”myParameter”> 脚本变量名称是myPatameter,它保存的请求参数的名称也是myParameter.

  7. 显示Bean属性 • <bean:write name=”myBean” property=”myProperty” scope=”request” filter=”true”/>

  8. 逻辑标记 •  条件逻辑 •  重复 •  转发/重定向响应

  9. 条件逻辑 • <logic:equal parameter=”name” value=”SomeName”> The entered name is SomeName </logic:equal> • <logic:greaterThan name=”bean” property=”prop” scope=”page” value=”7”> The value of bean.Prop is greater than 7 </logic:greaterThan>

  10. 存在标记 • <logic:notPresent name=”bean” property=”prop” scope=”page”> The bean property bean.prop is present </logic:notPresent>

  11. 重复标记 • <logic:iterate id=”currentInt” collection=”<% =myList %>” type=”java.lang.Integer” offset=”1” length=”2”> <% =currentint %> </logic:iterate>

  12. 转发和重定向标记 • 转发标记 <logic:forward name=”myGlobalForward”/> • 重定向标记 <logic:redirect name=”myGlobalForward”/>

  13. HTML标记 Struts HTML标记可以大致地分为以下几个功能: • 显示表单元素和输入控件 • 显示错误信息 • 显示其他HTML元素

  14. 显示表单元素和输入控件 • <html:form action=”validateEmploee.do” method=”post”> </html:form> • 复位和提交标记 <html:reset>和<html:submit>标记分别能够显示HTML复位按钮和提交按钮。 • 文本和文本区标记 <html:text>和<html:textarea>标记分别HTML文本框和文本区 • 检查框和复选框标记 <html:checkbox property=”married” value=”Y”/> • 单选钮标记 <html:radio>标记用来显示HTML单选钮控件

  15. 显示错误信息的标记 • <html:errors/> 显示集合中所有的错误。 • <html:errors property=”missing.name”/> 显示存储在missing.name关键字的错误。

  16. 其他HTML标记 struts HTML标记还定义了下列标记来显示其他HTML元素:  <html:html> : 显示HTML元素  <html:img> : 显示图象标记  <html:link> : 显示HTML链接或锚点  <html:rewrite> : 创建没有锚点标记的URI 这些标记的详细内容请参照struts文档。

  17. 模板标记 • 插入标记 <template:insert> • 放置标记 <template:put> • 获得标记 <template:get>

  18. 使用模板标记 template.jsp <html> <%@ taglib uri=”/template” prefix=”template” %> <head><title></title> </head> <body> <table width=”100%” height=”100%” > <tr height=”10%”> <td> <template:get name=”header”/> </td> </tr> <tr height=”80%”> <td> <template:get name=”content”/> </td> </tr> <tr height=”10%”> <td> <template:get name=”footer”/> </td> </tr> </table> </body> </html>

  19. 使用模板标记 <%@ taglib uri=”/template” prefix=”/template” %> <template:insert template=”template.jsp”> <template:put name=”header” content=”header.html”/> <template:put name=”content” content=”employeeList.jsp”/> <template:put name=”footer” content=”footer.html”/> </template:insert>

  20. 课后作业

More Related