今天倒腾了半天,终于是把这个两个框架整合到一起了。还是要写一下总结,同时给大家一些帮助。

开发环境:myeclipse 9.0(不好用!)tomcat6.0

1.准备工作

需要导入的包:struts2与spring基本的包就不用说了,我用的是struts2.1  Spring 3.0,

尤其要注意 别少导入的几个是:Spring3.0 Web Libraries  ;

struts支持spring的插件:struts2-spring-plugin-2.1.8.1.jar  将这个jar文件放到lib目录下

2.web.xml 的配置

除了struts2的核心配置外,我们还要加入spring的配置,代码如下:

<!--指明spring配置文件的位置!-->

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath*:applicationContext*.xml</param-value>

</context-param>

<!-加载spring的配置文件!-->

<listener>

<listener-class>

org.springframework.web.context.ContextLoaderListener

</listener-class>

</listener>

注:如果你在运行的时候发现有no found class org.springframework.web.context.LoaderListener 的异常 ,那你要注意你的Spring3.0 Web 包的导入了

3.application.xml 的配置

<beans>

<bean id="userService" class="com.test.service.UserServiceImpl"></bean>

<bean id="userAction" class="com.test.action.UserAction">

<property name="userService">

<ref bean="userService"/>

</property>

</bean>

</beans>

4.UserAction 类 这个不用多说,注意的是userService 属性的getter 和 setter 方法

public class UserAction {

private User user = new User();

public User getUser() {

return user;

}

public void setUser(User user) {

this.user = user;

}

private UserService userService;

public UserService getUserService()

{

return userService;

}

public void setUserService(UserService userService)

{

this.userService = userService;

}

public String checkLogin(){

if(userService.checkLogin(user))

{

System.out.println("ok");

}

else

System.out.println("sorry");

return "succ";

}

}

5.struts.xml 的配置,把原先class的路径换成spring中配置action的bean 的id

<struts> <package name="test" extends="struts-default">

<action name="login" class="userAction" method="checkLogin">

<result name="succ">index.jsp</result>

</action>

</package>

</struts>

最新文章

  1. Visual Studio 2012远程调试中遇到的问题
  2. Markdown语法说明(详解版)
  3. MySQL开启general_log跟踪sql执行记录
  4. hdu 5104 素数打表水题
  5. python 字节与字符串转换
  6. TKinter的常用组件
  7. HTTP上传文件探究
  8. 分类算法之贝叶斯(Bayes)分类器
  9. poj 1064 Cable master【浮点型二分查找】
  10. 自定义input file样式
  11. web并发模型
  12. PHP MySQL Update 之 Update
  13. 找出N之内的所有完数
  14. juddi学习一
  15. Linux常用命令速查-用户管理
  16. SpringCloud(4)---Ribbon服务调用,源码分析
  17. LinkedList阅读
  18. SimpleDateFormat未抛出ParseException
  19. 前端项目模块化的实践2:使用 Webpack 打包基础设施代码
  20. RF-获取上个月份

热门文章

  1. IIS特殊字符设置
  2. DG观察日志传输
  3. BZOJ4044: [Cerc2014] Virus synthesis(回文树+DP)
  4. mysql 多实例案例实战
  5. NIO专栏学习
  6. l洛谷 P3926 SAC E#1 - 一道不可做题 Jelly
  7. 《鸟哥的Linux私房菜-基础学习篇(第三版)》(四)
  8. 转换PHP脚本成为windows的执行程序
  9. dot-files/directories 点开头的文件或文件夹(windows/linux)
  10. JQuery源码解析 目录