Struts2 + Spring 整合(转)
的 id="loginAction" 保持一致,这里的这里和以前的struts1.x整合spring的时候不一样,因为strust1.x对action的管理是单例模式。
完成了上面的工作以后,只是相当于完成了整个项目的一半,而最为重要的 web.xml 的代码如下:
01<?xml version="1.0" encoding="UTF-8"?> 02<web-app version="2.5"?03?xmlns="http://java.sun.com/xml/ns/javaee"?04?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?05?xsi:schemaLocation="http://java.sun.com/xml/ns/javaee? 06?http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 07???08?<listener> 09??<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 10?</listener> 11?<filter> 12??<filter-name>struts2</filter-name> 13??<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>?? 14?</filter> 15?<filter-mapping>? 16??<filter-name>struts2</filter-name> 17??<url-pattern>/*</url-pattern> 18?</filter-mapping> 19??<welcome-file-list> 20????<welcome-file>index.jsp</welcome-file> 21??</welcome-file-list> 22</web-app> ?
这里最需要注意的是:
1<listener> 2?<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 3</listener> 它为服务器添加了一个监听器,这样也使的struts2 与 spring 结合起来。如果没有这句话,服务器是启动不了的。
剩下的就是一个success.jsp页面,这里就不再详说这个页面了。
完成了以后,启动服务器,如没有意外的话,系统会报错,说找不到 applicationContext.xml 配置文件,这个
时候我们停止服务器,把 applicationContext.xml 移动到 WebRoot中的WEB-INF目录下,重新启动服务器,
进入页面后输入用户名:LmxZz,密码:3348635 系统就会转到 success.jsp页面去了.
?
在spring2.0之前bean只有2种作用域即:singleton(单例)、non-singleton(也称prototype), Spring2.0以后,增加了session、request、global session三种专用于Web应用程序上下文的Bean。
1 楼 rapheal 2011-08-08 像Spring等Java的东西都能分到Web前端分类!? 2 楼 bbpbbf 2011-08-09 rapheal 写道像Spring等Java的东西都能分到Web前端分类!?不分到Web里,那Java Web算什么,ssh算什么,你说呢?