首先添加lib:

<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-config-browser-plugin</artifactId>
<version>2.3.20</version>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.20</version>
</dependency>

访问 http://localhost:8080/conv/config-browser/a.action 可以查看目前映射的所有路径

插件会按以下顺序执行:

1.寻找以下包:struts, struts2, action ,actions

任何深度找到的以上包都自动作为根目录

2.然后在包内寻找以下类:实现了com.opensymphony.xwork2.Action或者继承了com.opensymphony.xwork2.ActionSupport,或类名以Action结尾

3.映射为url:

com.example.actions.MainAction -> /main
com.example.actions.products.Display -> /products/display
com.example.struts.company.details.ShowCompanyDetailsAction -> /company/details/show-company-details(全部为小写)

比如,

会映射成,

可以跳过某些包:struts.convention.exclude.packages=org.apache.struts.*,org.apache.struts2.*,org.springframework.web.struts.*,org.springframework.web.struts2.*,org.hibernate.* (被跳过的包是无法再加入的,即使手动添加)

自动搜索的包名:struts.convention.package.locators=action,actions,struts,struts2

自动搜索的包名开头:struts.convention.package.locators.basePackage=

自动搜索的类名结尾:struts.convention.action.suffix=Action

手动指定具体包:struts.convention.action.packages=

4.默认,所有的Result都到这里去找:WEB-INF/content

如, ,则可以通过 http://localhost:8080/conv/my-jsp.action 访问到

可通过常量控制:struts.convention.result.path=/WEB-INF/content/

根据返回类型和返回字符串,要起不同的名字:

5.如果找不到这个页面文件,就认为这是个action,其他action可以在方法上添加@Action(“xx”),指明具体路径,这也就是Result Type为chain

中,

public class MyJsp extends ActionSupport {
public String execute() {
return "here";
}
}
public class HimJsp extends ActionSupport {
@Action("my-jsp-here") //通过指定为具体路径,实现chain,前提是没有那个页面文件
public String execute() {
return "yes";
}
}

最后会变成,

可以设置自动重载:

<constant name="struts.devMode" value="true"/>

<constant name="struts.convention.classes.reload" value="true" />

struts.convention.action.alwaysMapExecute =false  禁止自动调用execute()

struts.convention.action.disableScanning=true  禁用扫描

struts.convention.action.mapAllMatches =true  没有@Action也自动映射

struts.convention.action.name.lowercase=false  不要变成小写

struts.convention.action.name.separator=_  名称分隔符

struts.convention.action.eagerLoading=true  不使用Spring的时候可以提高性能

Struts Convention Plugin 流程 (2.1.6+)的更多相关文章

  1. struts2使用Convention Plugin在weblogic上以war包部署时,找不到Action的解决办法

    环境: struts 2.3.16.3 + Convention Plugin 2.3.16.3 实现零配置 现象:以文件夹方式部署在weblogic(10.3.3)上时一切正常,换成war包部署,运 ...

  2. Struts2 Convention Plugin ( struts2 零配置 )

    Struts2 Convention Plugin ( struts2 零配置 ) convention-plugin 可以用来实现 struts2 的零配置.零配置的意思并不是说没有配置,而是通过约 ...

  3. Struts2学习---拦截器+struts的工作流程+struts声明式异常处理

    这一节我们来看看拦截器,在讲这个之前我是准备先看struts的声明式异常处理的,但是我发现这个声明式异常处理就是由拦截器实现的,所以就将拦截器的内容放到了前面. 这一节的内容是这样的: 拦截器的介绍 ...

  4. Struts 2 执行流程 配置信息

    Struts 2 执行流程 首先,浏览器访问,经过Filter,Filter从src/struts.xml中寻找命名空间和action的名字,获取action类,从方法中拿到返回值,接着从result ...

  5. struts的工作流程

    - 一个请求过来,走前端控制器StrutsPrepareAndExecuteFilter        -前端控制器是一个过滤器,过滤器中的核心方法是doFilter(),doFilter方法中首先处 ...

  6. Struts 2的流程

    Struts 2的流程 一.Struts 2 的开发步骤: 在web.xml中定义核心的Filter来拦截用户的请求. 由于Web应用时基于请求/响应架构的应用,所以不管哪个MVC Web框架,都需要 ...

  7. Struts学习之流程汇总

    struts2 架构图如下图所示: 依照上图,我们可以看出一个请求在struts的处理大概有如下步骤: 1.客户端初始化一个指向Servlet容器(例如Tomcat)的请求: 2.这个请求经过一系列的 ...

  8. Struts Spring Plugin注意点

    Settings The following settings can be customized. See the developer guide. Setting Description Defa ...

  9. Struts 2开发基本流程

    Struts 2工作流程 Struts2是一个基于MVC设计模式的Web开发框架, 正如官网上介绍的那样: ApacheStruts 2 is an elegant, extensible frame ...

随机推荐

  1. 我 Git 命令列表 (1)【转】

    转自:http://www.microsofttranslator.com/bv.aspx?from=en&to=zh-CHS&a=http%3A%2F%2Fvincenttam.gi ...

  2. INDIGO STUDIO神器!快速创建WEB、移动应用的交互原型工具【转】

    转自:http://www.uisdc.com/indigo-studio-wireframe-interactive-uis 这套最新的设计工具出自Indigo工作室,永久免费,有mac版本和WIN ...

  3. Kernel rest_init相关

    Linux系统里,有些进程只有kernel部分的代码,即由一个kernel函数进入,在sched的时候,将其与用户进程同等对待. PID为0的叫swapper或sched进程,对应函数为rest_in ...

  4. linux系统的文件和文件类型

    文件 当你创建一个文件的时候,系统保存了有关该文件的全部信息,包括:• 文件的位置.• 文件类型.• 文件长度.• 哪位用户拥有该文件,哪些用户可以访问该文件.• i节点.• 文件的修改时间.• 文件 ...

  5. DBContext

    http://www.entityframeworktutorial.net/EntityFramework4.3/dbcontext-vs-objectcontext.aspx As you hav ...

  6. 如何从List<T>中筛选符合条件的数据的集合或个数

    方法一:Linq ChannelList就是一个List类型的数据,IsOpen 是其元素的属性 channelCount = (from channel in DevicesManager.Inst ...

  7. 通过两个GPS计算两个GPS点的距离

    public static double GetDistance(double lat1, double lng1, double lat2, double lng2) { double radLat ...

  8. gulp使用外部配置文件

    这很有好处,因为它使得任务很干净,并且 config.json 可以被其他的任务运行器(例如grunt)重复利用. config.json { "desktop" : { &quo ...

  9. Python风格规范

    Python风格规范 分号 Tip 不要在行尾加分号, 也不要用分号将两条命令放在同一行. 行长度 Tip 每行不超过80个字符 例外: 长的导入模块语句 注释里的URL 不要使用反斜杠连接行. Py ...

  10. 今天maven install时碰到的两个问题(堆溢出和编译错误)

    问题1.maven install时出现,日志如下: 系统资源不足.有关详细信息,请参阅以下堆栈追踪. java.lang.OutOfMemoryError: Java heap space at c ...