JSP外文翻译.pptx

上传人:摩西的****12 文档编号:144699936 上传时间:2020-09-13 格式:PPTX 页数:16 大小:141KB
返回 下载 相关 举报
JSP外文翻译.pptx_第1页
第1页 / 共16页
JSP外文翻译.pptx_第2页
第2页 / 共16页
JSP外文翻译.pptx_第3页
第3页 / 共16页
JSP外文翻译.pptx_第4页
第4页 / 共16页
JSP外文翻译.pptx_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《JSP外文翻译.pptx》由会员分享,可在线阅读,更多相关《JSP外文翻译.pptx(16页珍藏版)》请在金锄头文库上搜索。

1、附件 1:外文资料翻译译文,Struts一种开源MVC 的实现 这篇文章介绍 Struts,一个使用 servlet 和 JavaServer Pages 技术的一种 Model-View-Controller 的实现。Struts 可以帮助你控制 Web 项目中的变化并提高 专业化。即使你可能永远不会用 Struts 实现一个系统,你可以获得一些想法用于你 未来的 servlet 和 JSP 网页的实现中。 简介 在小学校园里的小孩子们都可以在因特网上发布 HTML 网页。然而,有一个 重大的不同在一个小学生和一个专业人士开发的网站之间。网页设计师(或者 HTML 开发人员)必须理解颜色、用

2、户、生产流程、网页布局、浏览器兼容性、图 像创建、JavaScript 等等。设计漂亮的网站需要做大量的工作,大多数 Java 开发 人员更注重创建优美的对象接口,而不是用户界面。JavaServer Pages (JSP) 技术为 网页设计人员和 Java 开发人员提供了一种联系钮带。 如果你开发过大型 Web 应用程序,你就理解“变化”这个词语。“模型-视图- 控制器”(MVC) 就是用来帮助你控制变化的一种设计模式。MVC 减弱了业务逻辑 接口和数据接口之间的耦合。Struts 是一种 MVC 实现,它将 Servlet 2.2 和 JSP 标记(属于 J2EE 规范)用作实现的一部分。

3、你可能永远不会用 Struts 实现一 个系统,但了解一下 Struts 或许使你能将其中的一些思想用于你以后的 Servlet 和 JSP 实现中。 模型-视图-控制器 (MVC) JSP 标签只解决了我们问题中的一部分。我们依然有验证、流控制、以及更新 应用程序结构的问题。这就是 MVC 从哪儿来以及来干嘛的。MVC 通过把问题分成 三类来帮助解决一些与单模块相关的问题: Model(模型) 模块包括应用程序功能的核心。模型封装着应用程序的各个结构。有时它所 包含的唯一功能就是结构。它对于视图或者控制器一无所知。,1,View(视图) 视图提供了模型的演示。它是应用程序的外表。视图可以进入

4、模型获得者, 但是它对于设置者一无所知。除此之外,它对于控制器也是一无所知。视图 仅仅当模型发生改变的时候才被通知。 Controller(控制器) 控制器对于用户的输入做出反应。它创造和设置模型。 MVC 模型 2 Web 给软件开发人员带来了一些独特的挑战,最显著的就是客户端和服务器端 的无结构连接。这种无结构连接行为使得模型很难知道视图的改变。在 Web 上,浏 览器必须重复询问服务器端以此来发现应用程序结构的改变。 另外一个显而易见的改变就是相对于模型或者控制器,视图采用了不同的技 术。当然,我们可以使用 Java(或者 PERL、C/C+ 或之前的其他代码)代码来 生成 HTML。这

5、种方法存在一些弊端: Java 程序员应该开发服务,而不是 HTML。 布局的改变将需要改变代码。 服务的客户将有能力去创造一些页面去满足他们的一些特殊需求。 页面设计人员将不能直接介入到页面的开发中。 嵌入在代码中的HTML 将会变得丑陋。 对于 Web,MVC 的经典形式将需要改变。图 4 展示了MVC 的 Web 适应,也 就是通常所说的MVC 模型 2 或者 MVC 2。. 图 4. MVC 模型 2,2,Struts,MVC 2 的一种实现,Struts 是一组相互协作的类、servlet 和 JSP 标记,它们组成一个可重用的 MVC 2 设计。这个定义表示 Struts 是一个框

6、架,而不是一个库,但 Struts 也包含 了丰富的标记库和独立于该框架工作的实用程序类。图 5 显示了 Struts 的一个概 览。 图 5. Struts 概览,3,Struts 概览 客户端浏览器 一个来自客户端浏览器的HTTP 创建一个事件。Web 容器将会用一个 HTTP 响应来作出响应。 控制器 控制器接收来自浏览器的请求,并决定发送请求到何处。就 Struts 而言,控 制器就是一个以 servlet 执行的一个命令设计模式。struts-config.xml 文件配 置控制器。 业务逻辑 业务逻辑更新模型的状态,并帮助控制应用程序的流。就 Struts 而言,这就 是通过作为实

7、际业务逻辑“瘦”包装的 Action 类完成的。 模型状态 模型代表了应用程序的状态。业务对象更新应用程序的状态。ActionForm bean 在会话级或请求级表示模型的状态,而不是在持久级。JSP 文件使用 JSP 标记读取来自 ActionForm bean 的信息。 视图 视图就是一个 JSP 文件。其中没有流程逻辑,没有业务逻辑,也没有模型,信息 - 只有标记。标记是使 Struts 有别于其他框架(如 Velocity)的因素 之一。 Struts 详细资料 在图 6 中展示了一个无其他附属设备的阿帕奇 struts 的 action 包的 UML 图表。 图 6 显示了 Acti

8、onServlet (Controller)、 ActionForm (Form State) 和 Action (Model Wrapper) 之间的最小关系。 图 6. 命令(ActionServlet) 与 模型 (Action if not, it will create an instance of the class. Struts will set the state of the UserActionForm using corresponding fields from the HttpServletRequest. No more dreadful request.getP

9、arameter() calls. For instance, the Struts framework will take fname from request stream and call UserActionForm.setFname(). The Struts framework updates the state of the UserActionForm before passing it to the business wrapper UserAction. Before passing it to the Action class, Struts will also cond

10、uct form state validation by calling the validation() method on UserActionForm. Note: This is not always wise to do. There might be ways of using UserActionForm in other pages or business objects, where the validation might be different. Validation of the state might be better in the UserAction clas

11、s. The UserActionForm can be maintained at a session level. Notes: The struts-config.xml file controls which HTML form request maps to which ActionForm. Multiple requests can be mapped UserActionForm. UserActionForm can be mapped over multiple pages for things such as wizards. The Action class The A

12、ction class is a wrapper around the business logic. The purpose of Action class is to translate the HttpServletRequest to the business logic. To use Action, subclass and overwrite the process() method. The ActionServlet (Command) passes the parameterized classes to ActionForm using the perform() met

13、hod. Again, no more dreadful request.getParameter() calls. By the time the event gets here, the input form data (or HTML form data) has already been translated out of the request stream and into an ActionForm class.,Figure 4. MVC Model 2,Struts, an MVC 2 implementation Struts is a set of cooperating

14、 classes, servlets, and JSP tags that make up a reusable MVC 2 design. This definition implies that Struts is a framework, rather than a library, but Struts also contains an extensive tag library and utility classes that work independently of the framework. Figure 5 displays an overview of Struts. F

15、igure 5. Struts overview,Struts overview Client browser An HTTP request from the client browser creates an event. The Web container will respond with an HTTP response. Controller The Controller receives the request from the browser, and makes the decision where to send the request. With Struts, the

16、Controller is a command design pattern implemented as a servlet. The struts-config.xml file configures the Controller. Business logic The business logic updates the state of the model and helps control the flow of the application. With Struts this is done with an Action class as a thin wrapper to the actual business logic. Model state The model represents the state of the application. The business objects update the application state. ActionForm bean represents the Model state at a se

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号