参考说明地址:http://struts.apache.org/2.1.6/docs/convention-plugin.html
Action:
@Results(value = { @Result(name = "success", location = "success.jsp"),
@Result(name = "error", location = "error.jsp"),
@Result(name = "testMethod", location = "/testMethod.jsp") })
public class AnnotationAction extends ActionSupport {
public String success() {
System.out.println("success method !");
return SUCCESS;
}
public String error() {
System.out.println("error method !");
return ERROR;
}
public String testMethod() {
System.out.println("testMethod method !");
return "testMethod";
}
}
struts.xml:
<struts>
<constant name="struts.i18n.encoding" value="GBK" />
<constant name="struts.devMode" value="true" />
<constant name="struts.configuration.xml.reload" value="true"/>
<constant name="struts.convention.result.path" value="/WEB-INF/jsp" />
<constant name="struts.convention.classes.reload" value="true" />
<constant name="struts.convention.package.locators" value="do,action"/>
<constant name="struts.convention.action.name.separator" value="-" />
<package name="default" namespace="/index" extends="struts-default">
<action name="test" class="com.jungle.action.TestAction">
<result>/index.jsp</result>
</action>
</package>
</struts>
jsp页面:
其中error.jsp和success.jsp都是放在WebRoot/WEB-INF/jsp文件夹下。
testMethod.jsp放在WebRoot下。
<a href="<%=path%>/annotation!success.action" >annotation!success.action</a>
<a href="${pageContext.request.contextPath}/annotation!error.action" >annotation!error.action</a>
<a href="${pageContext.request.contextPath}/annotation!testMethod.action" >annotation!testMethod.action</a>
分享到:
相关推荐
struts2-convention-plugin-2.3.24.1
struts2-convention-plugin-2.3.15.1.jar
struts2-convention-plugin-2.1.6.jar
struts2-convention-plugin-2.1.8.jar
struts2-convention-plugin-2.3.1.2.jar
struts2-convention-plugin-2.3.1.jar,使用注解的方式代替xml配置action,必须要引用这个包。
struts2-convention-plugin-2.3.32
struts2-convention-plugin-2.3.24.jar
不论高低版本,要使用struts2-core这个jar包,当又需struts2-convention-plugin.jar时勿必要使两者版本一致哦,否则会有DefError、Unable to read class诸等错误
struts2-convention-plugin-2.3.15.3.jar struts2配置Action注解要用到的包,真正实现零配置
struts2-convention-plugin-2.3.4.1.jar
struts2-convention-plugin-2.1.8.1.jar
Struts开始使用convention-plugin代替codebehind-plugin来实现struts的零配置,使用Convention插件,你需要此JAR文件
### Struts采用Convention-Plugin实现零配置 #### Struts2框架简介 Struts2是Apache组织维护的一个开源项目,它是一个基于MVC模式的Web应用框架。Struts2继承了Struts1的优点,并在此基础上增加了许多新特性,比如...
在给定的文件"struts2-convention-plugin-2.3.32.jar"中,我们关注的是Struts2的Convention插件,版本号为2.3.32。这个插件是Struts2框架的一个重要组成部分,旨在提供更加灵活和自动化的配置方式。 Convention...
然而,随着版本的更新,Struts2引入了一个名为Convention Plugin的新特性,旨在简化配置过程,实现所谓的“零配置”开发。 **什么是Struts2 Convention Plugin?** Convention Plugin是Struts2的一个插件,它基于...
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行...
这个“struts2-convention-plugin-2.3.4-sources”是Struts2框架的一个插件——约定优于配置(Convention Over Configuration)插件的源代码版本,版本号为2.3.4。这个插件是Struts2核心功能的扩展,旨在简化项目...