搜索 Action
搜索 Action: 对于 Convention 插件, 它会自动搜索位于 action, actions, struts, struts2 包下的所有 Java 类, Convention 会把如下两种 Java 类当成 Acition 处理
所有实现了 Action 接口的 Java 类
所有类名以 Action 结尾的 Java 类
下面是符合 Conversion 插件的 Action 类:
org.simpleit.actions.LoginAction
org.simpleit.actions.book.Books(Books 实现了 Action 接口)
org.simpleit.action.LoginAction
org.simpleit.struts.action.book.BookAction
org.simpleti.struts2.emp.EmployeeAction
按约定映射命名空间
找到合适的 Action 类之后, Convention 插件会按约定部署这些 Action, 部署 Action 时, actions, action, struts, struts2 包会被映射为根命名空间, 而这些包下的子包则被映射成对应的命名空间:
org.simpleit.actions.LoginAction /
org.simpleit.actions.book.Books(Books 实现了 Action 接口) /book
org.simpleit.action.LoginAction /
org.simpleit.struts.action.book.BookAction /action/book
org.simpleti.struts2.emp.EmployeeAction /emp
按约定映射 Action
Action 的 name 属性(也就是该 Action 所要处理的 URL) 则根据该 Action 的类名映射. 映射 Action 的name 时, 遵循如下规则:
若该 Action 类名包含 Action 后缀, 将该 Action 类名的 Action 后缀去掉. 否则不作任何处理
将 Action 类名的驼峰写法转成中横线 (-) 写法: 所有字母小写, 单词之间使用 – 隔开.
例子:
org.simpleit.actions.LoginAction /login.action
org.simpleit.actions.book.Books(Books 实现了 Action 接口) /book/books
org.simpleit.action.LoginAction /login.action
org.simpleit.struts.action.book.BookAction /action/book/book.action
org.simpleti.struts2.emp.EmployeeAction /emp/employee.action
按约定映射 Result
默认情况下, Convention 总会到 WEB 应用的 WEB-INF/content 路径下定位物理资源, 定位资源的约定是: actionUrl + resultCode suffix. 当某个逻辑视图找不到对应的视图资源时, Conversion 会自动试图使用 actionUrl 作为物理资源.
例子:
org.simpleit.actions.LoginAction /WEB-INF/content/login.jsp 或 login-success.jsp
org.simpleit.actions.book.Books(Books 实现了 Action 接口) /WEB-INF/content/book/books-success.jsp 或 books.jsp
org.simpleit.struts.action.book.BookAction /WEB-INF/action/book/book-success.jsp 或 book.jsp
org.simpleti.struts2.emp.EmployeeAction /WEB-INF/content/emp/employee-success.jsp 或 employee.jsp
Action 链的约定
如果希望一个 Action 处理结束后不是进入视图页面, 而是进行另一个 Action 形成 Action 链. 通过 Conversion 插件则只需遵守如下三个约定即可.
第一个 Action 返回的逻辑视图字符串没有对应的视图资源
第二个 Action 与第一个 Action 处于用一个包下
第二个 Action 映射的 URL 为: firstActionUrl + resultCode。
相关推荐
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...
从struts2.1版本开始,Convention Plugin作为替换替换Codebehind Plugin来实现Struts2的零配置。
简述STRUTS2_Convention零配置
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...
struts2采用convention-plugin实现零配置,讲述如何不通过配置文件搭建struts2
你可以通过设置struts.convention.package.locators属性来修改这个配置。如: <constant name="struts.convention.package.locators" value="web,action" /> 则定义了在项目中,包路径包含web和action的将被视为...
如何使用插件convention来实现struts2框架的零配置以及整合ssh架构
NULL 博文链接:https://lijiejava.iteye.com/blog/1849166
struts2的convention配置详解 很全
从struts2.1版本开始,Convention Plugin作为替换替换Codebehind Plugin来实现Struts2的零配置。 • 包命名习惯来指定Action位置 • 命名习惯制定结果(支持JSP,FreeMarker等)路径 • 类名到URL的约定转换 • 包名...
struts2-convention-plugin-2.3.15.1.jar
struts2 spring4 hibernate4 Struts2零配置基本架包 struts2-json-plugin-2.5.5.jar struts2-convention-plugin-2.5.5.jar
stuts2 项目开发action 类 action 视图文件约定规则
Struts2插件convention
struts2-convention-plugin-2.3.32
struts-convention实现零配置
从 Struts 2.1 开始,Struts 2 改为使用 Convention 插件来支持零配置。Convention 插件彻底地抛弃了配置信息,不仅不需要使用 struts.xml 文件进行配置,甚至不需要使用 Annotation 进行配置。而是由 Struts 2 根据...