在struts.xml中我们可以写<action name="login" class="com.zzh.web.loginAction"></action>
通过form 中指定的login.action跟class相关联,在Struts2 convention 可以自动去找到,
<!-- [if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!-- [if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" LatentStyleCount="156">
</w:LatentStyles>
</xml><![endif]-->
<!--
/* Font Definitions */
@font-face
{font-family:Courier;
panose-1:2 7 4 9 2 2 5 2 4 4;
mso-font-alt:"Courier New";
mso-font-charset:0;
mso-generic-font-family:modern;
mso-font-format:other;
mso-font-pitch:fixed;
mso-font-signature:3 0 0 0 1 0;}
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:Verdana;
panose-1:2 11 6 4 3 5 4 4 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:536871559 0 0 0 415 0;}
@font-face
{font-family:"\@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:宋体;
mso-font-kerning:1.0pt;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
<!-- [if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
默认情况下,
Convention
会找到
com.opensymphony.xwork2.Action
的实现类,或制定包中以
Action
结尾的类
action
Convention
使用以下方法来搜索类路径,首先,
Convention
会从根
package
中寻找包名含有
struts
, struts2
, action
or actions
的任意
packages
。下一部,
Convention
从前一步找到的
package
以及其子
package
中寻找
com.opensymphony.xwork2.Action
的实现以及以
Action
结尾的类,下面为
Convention
寻找的类
Classes
com.example.actions.MainAction
com.example.actions.products.Display
(
implements
com.opensymphony.xwork2.Action)
com.example.struts.company.details.ShowCompanyDetailsAction
每一个被
Convention
找到
action
都会对应一个明确的
URL
地址,
URL
以
package
的名字以及
Action
类名为基础。
首先
Convention
从根
package
以及类所在的
package
名来确定对应的
URL
中的路径(
namespace
)
我们也可以指定找出哪个包下的classs,只要在struts.xml中指定
<constant name="struts.convention.package.locators" value="web" />
这样这可以从web 包下找到,
如果包这样的如com.zzh.web.security.userAction
要在jsp中调用userAction只要 security/user.action 就可以了。
分享到:
相关推荐
Struts2的Convention插件是一种自动化配置工具,从2.1版本开始引入,旨在减少XML配置,实现Struts2应用的零配置或者最少配置。该插件通过一系列预定义的命名规则和约定,自动解析和映射Action、结果页面、拦截器等...
在Struts2的某个版本之后,引入了一项名为`convention-plugin`的新特性,旨在简化配置过程,实现所谓的“零配置”开发。这个插件允许开发者通过约定而非显式配置来设置Action类、结果页面等,从而减少了XML配置文件...
2. **结果路径**:默认情况下,结果页面位于`WEB-INF/content`目录下,但可通过配置属性`struts.convention.result.path`更改。 3. **类名到URL**:类名通常被转换为小写的URL,如`MyAction` -> `my-action`。 4. ...
Convention 插件可以通过设置 struts-plugin.xml 文件中的 <constant name="struts.convention.package.locators" value="action,actions,struts,struts2"/> 来配置 Action 类存在的路径搜索包。这个配置将所有包含...
Struts2 Convention Plugin 是一个用于简化 Struts2 配置的插件,自 Struts2.1 版本起引入,旨在实现零配置或者最少配置的开发环境。它通过一系列预定义的规则和约定,自动将请求映射到相应的 Actions 和结果页面,...
默认所有的结果页面都存储在WEB-INF/content下,你可以通过设置struts.convention.result.path这个属性的值来改变到其他路径。如: Xml代码 <constant name="struts.convention.result.path" value="/WEB-INF/page" ...
- 结果页面默认路径:通常位于`WEB-INF/content`下,可通过`struts.convention.result.path`属性调整。 - 通过配置属性或覆盖类方法可以控制和扩展约定。 6. **在JAR文件中的Action** - 支持在JAR文件内定义...
- 下载Struts2的核心库,通常包括`struts2-core`, `struts2-convention-plugin`, `struts2-json-plugin`等JAR文件,以及相关的依赖库,这些可以从Apache Struts官方网站获取。 2. **创建新项目**: - 打开Eclipse...
2. **结果路径**:Action的结果路径通常是基于Action类名的,例如`HelloWorld`Action的默认结果可能是`hello-world.jsp`或`hello-world.ftl`,这些文件通常位于`WEB-INF/content`目录下,但可以通过配置`struts....
同时,确保`struts2-convention-plugin`或`struts2-core`库包含在项目依赖中,它们包含了文件上传所需的组件。 2. **创建表单** 在HTML或JSP页面中,创建一个`<form>`标签,设置`enctype`属性为`multipart/form-...
Struts2框架集成了一个名为`struts2-convention-plugin`的插件,它提供了文件上传的支持。主要依赖于`Commons FileUpload`和`Commons IO`这两个Apache的开源库,它们处理了文件上传的细节,如内存限制、临时文件...
10. struts2-convention-plugin.jar 将这些jar文件复制到项目的WEB-INF/lib目录下,然后右键点击项目,选择Build Path -> Configure Build Path,将这些库添加到项目的类路径中。 为了使Struts2框架正常工作,我们...
如果你使用的是非Maven项目,可以从Apache Struts官方网站下载所需的JAR包,包括struts2-core、struts2-convention-plugin等,并将它们添加到你的项目类路径中。在Eclipse中,可以右键点击项目 -> Build Path -> ...
- `struts2-convention-plugin.jar` (可能根据需求添加) 在Liferay中,可能还需要其他依赖,例如`servlet-api.jar`和`portlet-api.jar`等。如果遇到错误,可以根据错误提示逐步添加缺失的库。 ### 二、新建Liferay...
在Struts2中,文件上传主要依赖于`struts2-convention-plugin`和`struts2-file-uploading-plugin`这两个插件。要实现文件上传,你需要在Action类中定义一个字段,类型为`java.io.File`或`org.apache.struts2....
最后,别忘了在项目中添加Struts2的FileUpload相关的依赖库,例如`struts2-convention-plugin`和`struts2-core`,以及可能需要的其他库,如`commons-fileupload`和`commons-io`,这些JAR包通常会包含在描述中提到的...
从你的本地存储库中找到Struts2的核心库,包括struts2-core、struts2-convention-plugin、struts2-java5-plugin等,并添加到项目中。 3. **配置web.xml**: - 在"WebContent/WEB-INF/"目录下打开web.xml文件,添加...
添加以下代码来启用`struts2-convention-plugin`和`struts2-file-uploading-plugin`: ```xml <constant name="struts.multipart.maxSize" value="10485760"/> <!-- 设置最大上传文件大小 --> ...