<!-- /* Font Definitions */ @font-face {font-family:"MS 明朝"; panose-1:2 2 6 9 4 2 5 8 3 4; mso-font-alt:"MS Mincho"; mso-font-charset:128; mso-generic-font-family:roman; mso-font-pitch:fixed; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:SimSun; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:宋体; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:Century; panose-1:2 4 6 4 5 5 5 2 3 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:647 0 0 0 159 0;} @font-face {font-family:"/@MS 明朝"; panose-1:2 2 6 9 4 2 5 8 3 4; mso-font-charset:128; mso-generic-font-family:roman; mso-font-pitch:fixed; mso-font-signature:-1610612033 1757936891 16 0 131231 0;} @font-face {font-family:"/@SimSun"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0mm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:Century; mso-fareast-font-family:"MS 明朝"; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:99.25pt 30.0mm 30.0mm 30.0mm; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:18.0pt;} div.Section1 {page:Section1;} -->
工作机制:
Struts 的工作流程 :
在 web 应 用启 动时 就会加 载 初始化 ActionServlet,ActionServlet 从
struts-config.xml 文件中 读 取配置信息 , 把它 们 存放到各 种 配置 对 象
当 ActionServlet 接收到一个客 户请 求 时 , 将 执 行如下流程 .
-(1) 检 索和用 户请 求匹配的 ActionMapping 实 例 , 如果不存在 , 就返回 请 求路径无效信息 ;
-(2) 如果 ActionForm 实 例不存在 , 就 创 建一个 ActionForm 对 象 , 把客 户 提交的表 单 数据保存到 ActionForm 对 象中 ;
-(3) 根据配置信息决定是否需要表 单验证 . 如果需要 验证 , 就 调 用 ActionForm 的 validate() 方法 ;
-(4) 如果 ActionForm 的 validate() 方法返回 null 或返回一个不包含 ActionMessage 的 ActuibErrors 对 象 , 就表示表 单验证 成功 ;
-(5)ActionServlet 根据 ActionMapping 所包含的映射信息决定将 请 求 转发给 哪个 Action, 如果相 应 的 Action 实 例不存在 , 就先 创 建 这 个 实 例 , 然后 调 用 Action 的 execute() 方法 ;
-(6)Action 的 execute() 方法返回一个 ActionForward 对 象 ,ActionServlet 在把客 户请 求 转发给 ActionForward 对 象指向的 JSP 组 件 ;
-(7)ActionForward 对 象指向 JSP 组 件生成 动态 网 页 , 返回 给 客 户 ;
为 什 么 要用:
JSP 、 Servlet 、 JavaBean 技 术 的出 现给 我 们 构建 强 大的企 业应 用系 统 提供了可能。 但用 这 些技 术 构建的系 统 非常的繁乱,所以在此之上,我 们 需要一个 规则 、一个把 这 些技 术组织 起来的 规则 , 这 就是框架, Struts 便 应 运而生。
基于 Struts 开发 的 应 用由 3 类组 件构成:控制器 组 件、模型 组 件、 视图组 件
8 . Struts 的 validate 框架是如何 验证 的?
在 struts 配置文件中配置具体的 错误 提示,再在 FormBean 中的 validate() 方法具体 调 用。
9 . 说 下 Struts 的 设计 模式
MVC 模式 : web 应 用程序启 动时 就会加 载 并初始化 ActionServler 。用 户 提交表 单时 ,一个配置好的 ActionForm 对 象被 创 建,并被填入表 单 相 应 的数 据, ActionServler 根据 Struts-config.xml 文件配置好的 设 置决定是否 需要表 单验证 ,如果需要就 调 用 ActionForm 的 Validate () 验证 后 选择 将 请 求 发 送到哪个 Action ,如果 Action 不存在, ActionServlet 会先 创 建 这 个 对 象,然后 调 用 Action 的 execute ()方法。 Execute ()从 ActionForm 对 象中 获 取数据,完成 业务逻辑 ,返回一个 ActionForward 对 象, ActionServlet 再把客 户请 求 转发给 ActionForward 对 象指定的 jsp 组 件, ActionForward 对 象指定的 jsp 生成 动 态 的网 页 ,返回 给 客 户 。