1.添加spring支持
2.添加Struts2的spring插件
struts2-spring-plugin-2.0.11.jar
3.在web.xml中添加监听器,启动spring容器
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
4.添加service接口和实现类代码,并在LoginAction中调用
5.applicationContext.xml中配置bean
首先修改struts.xml中<action name="login" class="loginAction">
并添加登录失败返回页error.jsp
添加:
<bean id="loginService"class="com.ascent.service.impl.ILoginServiceImpl"/>
<bean id="loginAction" class="com.ascent.action.LoginAction">
<property name="loginService">
<ref local="loginService" />
</property>
</bean>
6.启动服务器运行
启动后运行,登录后得到成功效果, Struts2整合Spring2完成