步骤:
1.导入Struts的jar包,
红色标注的为注解必须要用的包
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
freemarker-2.3.15.jar
ognl-2.7.3.jar
struts2-codebehind-plugin-2.1.8.1.jar
struts2-core-2.1.8.1.jar
xwork-core-2.1.6.jar
2.配置web.xml过滤器,
红色为必须注意的地方.不用注解的过滤器可以忽略此段内容.初始化的名字(actionPackages)固定不变.value(com.meiyoudao)为你写的action类所在的包路径.过滤器会根据此内容去找匹配的action类.多个包用,号分隔.
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.meiyoudao</param-value>
</init-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.meiyoudao</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3.写Action类,继承ActionSupport类.注意两个类的名称和所访问的URL的区别
代码实例,访问的RUL为:http://localhost/站点名称/ok.action
package com.meiyoudao;
import org.apache.struts2.config.Namespace;
import org.apache.struts2.config.Result;
import com.opensymphony.xwork2.ActionSupport;
@Namespace("/")
@Result(name = "SUCCESS", value = "/index1.jsp")
public class OkAction extends ActionSupport {
@Override
public String execute() throws Exception {
System.out.println("================");
return "SUCCESS";
}
}
代码实例,访问的RUL为:http://localhost/站点名称/haha.action
package com.meiyoudao;
import org.apache.struts2.config.Result;
import com.opensymphony.xwork2.ActionSupport;
@Result("/index.jsp")
public class Haha extends ActionSupport {
@Override
public String execute() throws Exception {
System.out.println("+++++++++++++");
return "success";
}
}
分享到:
相关推荐
本文档对利用struts2 注解 annotation 实现文件下载作了简单介绍,并有代码为例,希望对学习struts2注解annotation的人有帮助,特别是需要动态传参方面。
struts2 annotation 注解的详细介绍及使用方法
参考博文:http://blog.csdn.net/u011638419/article/details/41743049
而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行配置,甚至不需要使用Annotation进行配置,而是由struts2根据约定...
而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用struts.xml文件进行配置,甚至不需要使用Annotation进行配置,而是由struts2根据约定...
NULL 博文链接:https://vincenta.iteye.com/blog/1535330
用注解(annotation)方式配置struts2 (webwork) 中action的拦截器(interceptor)
从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件...甚至不需要使用Annotation进行配置,而是由struts2根据约定自动配置。
struts2,json-plugin, 并全注解零配置
自己学Struts的注解,写的一个零配置小demo。 很简单很简单,只供新手学习。
基于注解Annotation的最新版SSH(Struts2.3.7+Hibernate4.1.9+Spring3.2.0)整合开发,真正实现零配置。 最新版本Struts、Spring、Hibernate框架整合: struts-2.3.7 spring-framework-3.2.0.RELEASE hibernate-...
struts2 注解与Action相关的两个Annotation是@Action 和@Actions2)@Action中可指定一个value属性。类似于指定””/>属性值
超级详细的SSH2项目实例详解,并且附带两个项目详解。两种注解实现方式。...在JavaEE企业级开发中,以SSH2框架为核心的应用非常广,大象根据项目实践经验,通过二个实例,详细的为大家讲解如何实现全注解式的开发。
1、shiro+strut2 2、shiro注解 + struts2注解 2、shiro 缓存:因为使用了缓存,第一使用admin登录,如果没有logout,再用test登录,则test具有admin的权限
spring+hibernate3.2+struts2.0 注解,超级简化,省略hbm.xml、bean注入xml配置等,一切annotation
SSH2 annotation 实现struts2.1.6 spring2.5.6 hibernate3.3 全注解开发 hibernate延迟加载_懒加载 具体应用
springmvc注解.doc,Spring注解讲解.doc,struts2标签详解.pdf,struts2常用标签.pdf,Struts2页面开发中常用标签.pdf,Struts2注解详细说明文档.doc,Hibernate注解教程:Hibernate Annotation使用实例.maff
配置web.xml,加入注解,验证注解,Convention的Annotation ,、与Result配置相关的Annotation
Spring3Annotation+Struts2Annotation+Hibernate3Annotation 全注解集成开发,操作Emp表
全注解,演示Struts2 + Spring + MyBatis整合,开发环境为Eclipse,数据库为mysql。