Struts2框架的特点 与JSP/Servlet技术对比,Struts2框架的特点: ·Mode I层没有区别:包括EJB等; ·Controller层区别最大: √包含过滤器、拦截器和Action(数量最多的业务控制器)三个层次; √拦截器自动拦截请求参数,并封装到Act ionf的属性(属性驱动)或对象 (模型驱动)中; √Action可独立于Web容器=》单元测试; √页面导航在struts.xml中配置,无需硬编码。 。View层: √可包括JSP、FreeMarker、Velocity; √提供了能实现如输入信息回填、校验信息显示等动态功能的强大标签库, 也可使用JSTL其他标签库。 ·其他优点:如可配置的输入校验、便捷的国际化编程等。 Struts.入门 6。 西北农林升教大学信息工程学院本科生课程
❖ 与JSP/Servlet技术对比,Struts 2框架的特点: • Model层没有区别:包括EJB等; • Controller层区别最大: ✓ 包含过滤器、拦截器和Action(数量最多的业务控制器)三个层次; ✓ 拦截器自动拦截请求参数,并封装到Action的属性(属性驱动)或对象 (模型驱动)中; ✓ Action可独立于Web容器 ===》单元测试; ✓页面导航在struts.xml中配置,无需硬编码。 • View层: ✓ 可包括JSP、FreeMarker、Velocity; ✓ 提供了能实现如输入信息回填、校验信息显示等动态功能的强大标签库, 也可使用JSTL其他标签库。 • 其他优点:如可配置的输入校验、便捷的国际化编程等。 Struts 2框架的特点 Struts入门 •6 信息工程学院本科生课程
Apache主页对于Struts2的叙述 http://struts.apache.org/2.x/index.html: Apache Struts 2 is an elegant,extensible framework for creating enterprise-ready Java web applications. The framework is designed to streamline the full development cycle,from building,to deploying,to maintaining applications over time. Apache Struts 2 was originally known as WebWork 2. After working independently for several years,the WebWork and Struts communities joined forces to create Struts2.This new version of Struts is simpler to use and closer to how Struts was always meant to be. Struts入门 ·7。西北农林升技大学信息工程学院本科生课程
❖ http://struts.apache.org/2.x/index.html: • Apache Struts 2 is an elegant, extensible framework for creating enterprise-ready Java web applications. The framework is designed to streamline the full development cycle, from building, to deploying, to maintaining applications over time. • Apache Struts 2 was originally known as WebWork 2. After working independently for several years, the WebWork and Struts communities joined forces to create Struts2. This new version of Struts is simpler to use and closer to how Struts was always meant to be. Apache主页对于Struts 2的叙述 Struts入门 •7 信息工程学院本科生课程
Struts2简单实例的运行过程 ”用户提交请求; FilterDispatcher过滤请求,并调用Act i onMapper 以确定是否需调用Action。如需调用,Act ionMapper 通知FilterDispatcher将请求处理交给Act ionProxy; Act ionProxy:通过Configuration Manager解析框架 的配置文件struts.xml,找到需要调用的Action类。 同时,ActionProxy实例化ActionInvocation; ActionInvocation实例调用与Act ion有关的拦截器 以及Action类的execute.方法。Action执行完毕后, Act ionInvocat ion根据struts.xml中配置的action 的相应result,将页面导航到指定URL。 Struts.入门 ·8。西北农林科枝大学信息工程学院本科生课程
❖ 用户提交请求; ❖ FilterDispatcher过滤请求,并调用ActionMapper 以确定是否需调用Action。如需调用,ActionMapper 通知FilterDispatcher将请求处理交给ActionProxy; ❖ ActionProxy通过Configuration Manager解析框架 的配置文件struts.xml,找到需要调用的Action类。 同时,ActionProxy实例化ActionInvocation; ❖ ActionInvocation实例调用与Action有关的拦截器 以及Action类的execute方法。Action执行完毕后, ActionInvocation根据struts.xml中配置的action 的相应result,将页面导航到指定URL。 Struts 2简单实例的运行过程 Struts入门 •8 信息工程学院本科生课程
Struts2工作原理 Struts 2 Architecture HttpServletRequest StrutsPrepareFilter ActionContextCleanUp Other Filters(SiteMesh,etc) StrutsExecuteFilter FilterDispatcher ActionMapper ActionProxy Interceptor 1 合成的: Interceptor 2 过滤器, 不 Action Configuration invocation Interceptor 3 Tag Subsystem Manager HTML,Dojo,Forms,etc Action Result ◆ struts.xml Template Interceptor 3 iSP,FreeMarker,Velocity,etc Interceptor 2 ! Interceptor 1 StrutsPrepareAndExecuteFilter HttpServletResponse Servlet Filters Struts CoreInterceptors (User Created Struts入门 9。 品址农林升教大学信息工程学院本科生课程
Struts入门 •9 信息工程学院本科生课程 Struts 2工作原理 StrutsPrepareFilter StrutsExecuteFilter StrutsPrepareAndExecuteFilter 合成的 过滤器