关键还是基于Annotation的方式配置Struts2,使用的版本是2.1.6.
纯为个人记忆,及以后方便使用
Struts2需要的就是一个在classpath下的struts.xml 配置如下,不过大多可以省略.
<?xml version="1.0" encoding="UTF-8" ?>
<!--指定struts2配置文件的DTD信息-->
<!DOCTYPE struts PUBLIC
"-//apache Software Foundation//DTD Struts Configuation 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<!-- struts 是struts2配置文件的根元素-->
<struts>
<!--设置Struts 2应用是否使用开发模式-->
<constant name="struts.devMode" value="true"></constant>
<!--每次Http请求到达时,是否重新加载资源文件-->
<constant name="struts.i18n.reload" value="true"></constant>
<!--struts.xml文件系统改变后,系统是否重新加载该文件-->
<constant name="struts.configuration.xml.reload" value="true"></constant>
<!--指定web应用的默认编码集-->
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<!--指定所需的国际化资源-->
<constant name="struts.custom.i18n.resources" value="messageResource"></constant>
<!--指定需要Struts 2处理请求的后缀-->
<constant name="struts.action.extension" value="jspa" />
<!--struts2的Action必须放在指定的包空间下定义-->
<package name="strutsqs" extends="struts-default">
<global-results>
<!-- 当返回login视图名时,转入/login/login.jsp页面登录 -->
<result name="common_error">/deal/error.jsp</result>
</global-results>
</package>
<include file="struts-user.xml"></include>
</struts>
需要的jar包如下
freemarker-2.3.13.jar //有些地方需要用到
struts2-codebehind-plugin-2.1.6.jar //用于配置Annotation风格
struts2-config-browser-plugin-2.1.6.jar //同上
struts2-core-2.1.6.jar //核心包
struts2-spring-plugin-2.1.6.jar //用于和Spring集成
xwork-2.1.2.jar //另外个核心包
ognl-2.6.11.jar //依赖包
javassist-3.4.GA.jar //同期需要的一个包..用于Junit和Spring集成的使用
@ParentPackage("struts-default") //用于指定默认的包,继承的作用
@Namespace("") //声明一个空的命名空间
@Results( { @Result(value = "/sayHello.jsp") }) //判断返回结果,默认是name是success,其他可以自定义
public class HelloAction extends ActionSupport {
public String SayHello() {
System.out.println("欢迎使用action");
return "success";
}
public String execute() {
System.out.println("Access Success!!!");
return "success";
}
}
这里注意访问的Action中,名称是类名的第一个小写hello.action,其中后面的Action部分可以不写
其他就是在web.xml里面配置
<!--用于加载Spring配置文件-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml
</param-value>
</context-param>
<!-- Character Encoding filter 编码过滤器 (可选) -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Struts2 filter,actionPackages定义扫描Action类的目录,和Annotation配置有关 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.orz.view.struts</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<!--Spring ApplicationContext 载入 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- Spring 刷新Introspector防止内存泄露(可选) -->
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener>
分享到:
相关推荐
struts2 使用Annotation配置实现的小例子,转载供大家学习使用,里面包括了所需的jar包
struts2-Annotation
参考博文:http://blog.csdn.net/u011638419/article/details/41743049
struts2 annotation 注解的详细介绍及使用方法
博文链接:https://flym.iteye.com/blog/174358
自己学Struts的注解,写的一个零配置小demo。 很简单很简单,只供新手学习。
用注解(annotation)方式配置struts2 (webwork) 中action的拦截器(interceptor)
本文档对利用struts2 注解 annotation 实现文件下载作了简单介绍,并有代码为例,希望对学习struts2注解annotation的人有帮助,特别是需要动态传参方面。
基于Annotation的s2sh整合配置实现分页功能基于Annotation的s2sh整合配置实现分页功能基于Annotation的s2sh整合配置实现分页功能基于Annotation的s2sh整合配置实现分页功能基于Annotation的s2sh整合配置实现分页功能
马士兵视频里的struts2 hibernate3 spring2.5 annotation 整合 绝对好用 里面还有jar包 部署就可以用
jquery easyUI+struts2+spring+hibernate基于annotation实现的CRM
struts2,json-plugin, 并全注解零配置
Struts2中使用annotation实现零配置
NULL 博文链接:https://vincenta.iteye.com/blog/1535330
初学者很好的学习资料哦,注意哦,这可是基于annotation的 SSH哦,xml的时代已经过去了
Struts2的“零配置”特性是Struts2的新功能,可能会出现一些小Bug,所以企业开发者请慎重使用该特性, ...如果用的是Annotation的Struts2,就要将struts.xml去掉,否则即使将struts.xml中的内容注销,也会报错;
基于Annotation的Struts2.0+Hibernate3.3+Spring2.5整合开发
基于annotation s2sh实现零配置的CRM
struts2 annotion helloworld 源代码,适合初学者看看,不懂得看看文档就知道了。
ssh2框架整合模板。 spring2.5.6,hibernate3.2 基于annotation配置,配置文件内容很少 struts2基于模式匹配,配置文件也很简单。