---
title: "struts2 convention plugin笔记"
author: "name327"
date: "2012-06-01T22:14:05Z"
tags: []
categories: ["编程语言"]
slug: "struts2-convention-plugin"
draft: false
lastmod: "2012-06-01T22:17:21Z"
id: 1547014
url: "https://name327.iteye.com/blog/1547014"
---

要保证Conventtion plugin可以找到我们的action类。默认情况下，Convention plugin将找到所有的action类，当然前提是，这个些类已经实现了（implement） com.opensymphony.xwork2.Action接口，或者这些类得名字以Action结尾，并且这些类存放的特定包名，包名中必须包含这些中的一个 struts, struts2, action or actions。

例如：

action类得名字以Action结尾

com.example.actions.MainAction

action类实现了com.opensymphony.xwork2.Action接口

com.example.actions.products.Display (implements com.opensymphony.xwork2.Action)

action类名字以Action结尾。

com.example.struts.company.details.ShowCompanyDetailsAction

以上的action类都可以被convention plugin所找到。

 

注意:

如果没有implements com.opensymphony.xwork2.Action 并且没有 extends com.opensymphony.xwork2.ActionSupport的情况下必须要有execute()方法，否则扫描不到

\----------------------------------------------

这些action类的命名空间如下所示（每个action，配置时候都会有命名空间namespace，如果不配置则命名空间为/）

com.example.actions.MainAction -&gt; /

com.example.actions.products.Display -&gt; /products

com.example.struts.company.details.ShowCompanyDetailsAction -&gt; /company/details

URL规则是以struts, struts2, action or actions 为基础的。

\-----------------------------------------------

在浏览器访问action的URL如下所示

com.example.actions.MainAction -&gt; /main

com.example.actions.products.Display -&gt; /products/display

com.example.struts.company.details.ShowCompanyDetailsAction -&gt; /company/details/show-company-details

URL规则是，如果以Action结尾的action类，URL就是为类的首字母变为小写，然后后面的其他的首字母也小写单词都以“-”隔开

\---------------------------------------------------------

 

 

无聊翻出笔记，贴上来