Sturts目前分为两个框架:
(1)是传统的Struts1和WebWork接合后的Struts框架,Struts2核心为WebWork;
(2)是Shale,Shale是面向服务器架构,是建立在JSF上。
简述Struts1与Struts2区别:
①Action类:Struts2的Action类可以实现一个Action接口或其他接口,而Struts1类只继承一个抽象基类(使用的是抽象基类编程,而不是接口),Struts2提供一个ActionSupport基类去实现常用接口,Struts2的接口不是必须的。
②Servlet依赖:Struts2的Action不依赖于容器,Struts1的Action依赖于Servlet的API。
③表达式语言:Struts2在Struts1整合的JSTL基础上,支持一个更加强大和灵活的表达式语言OGNL(object Graph Notation Language)。
④线程模式:Struts1的Action是单例模式并且是线程安全的,因为仅有Action的一个实例处理所有的请求;Struts2的Action为每一个请求产生一个实例没有线程安全的问题。
⑤Action的执行控制:Struts1支持每个模块有单独的生命周期,但模块中的所有Action必须共享相同的生命周期,而Struts2支持通过拦截器堆栈为每个Action创建不同的生命周期,堆栈能够根据需要和不同的Action一起使用。
Sturts2的体系结构图:
通过Struts2体系结构图可知:Sturts2使用拦截器做为处理流以用户的业务逻辑控制为目标,创建一个控制器代理,该代理负责处理用户请求,毁掉业务控制器的execute方法,给用户返回一个可见视图资源。
Sturts2的配置文件:
Sturts2通常需要配置Action的sturts.xml和Action全局属性的sturts.properties文件。
sturts.xml配置文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="first" extends="struts-default">
<action name="hello" class="action.logionAction" method="{1}">
<result name="success">/hello.jsp</result>
</action>
</package>
</struts>
sturts.properties配置文件:
#指定Struts2 处于开发状态
sturts.dovMode = false
#指定当Struts2配置文件改变后,web框架是否重新加载Struts2配置文件
sturts.configuration.xml.reload = ture
sturt2最重要的配置:web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
以上内容均为个人在学习过程中的笔记资料,也是对Sturts2的概况理解,下篇将会学习sturt2的基本流程。