13.spring与struts整合
来源:互联网 发布:恶搞老鼠软件 编辑:程序博客网 时间:2024/06/07 00:35
1、web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 1. struts配置 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 2. spring 配置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/bean-*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
2、struts.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <package name="user" extends="struts-default"> <action name="user" class="userAction" method="execute"> <result name="success">/index.jsp</result> </action> </package></struts>
3、bean-service.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="userService" class="cn.itcast.service.UserService"> <property name="userDao" ref="userDao"></property> </bean></beans>
4、bean-dao.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="userDao" class="cn.itcast.dao.UserDao" scope="singleton" lazy-init="false"></bean></beans>
5、bean-action.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 指定action多例 --> <bean id="userAction" class="cn.itcast.action.UserAction" scope="prototype"> <property name="userService" ref="userService"></property> </bean></beans>
6、UserService
public class UserService { //IOC容器注入 private UserDao userDao; public void setUserDao(UserDao userDao) { this.userDao = userDao; } public void save() { userDao.save(); }}
7、UserDao
public class UserDao { public void save() { System.out.println("DB:保存用户"); }}
8、UserAction
public class UserAction extends ActionSupport { // springIOC容器注入 private UserService userService; public void setUserService(UserService userService) { this.userService = userService; } public String execute() { userService.save(); return SUCCESS; }}
0 0
- 13.spring与struts整合
- 整合Struts 与Spring
- 整合Struts 与Spring
- 整合Struts 与Spring
- struts与spring整合
- spring与struts整合
- Spring与Struts整合
- Spring与Struts整合
- Spring与struts整合
- Spring与Struts整合
- spring 与struts 整合
- struts与spring整合
- Spring与Struts整合
- spring与struts整合
- Spring与Struts如何整合
- Struts与Spring的整合
- Spring 与 struts 2 整合
- struts与spring的整合
- cocoapods的安装和使用以及版本升级遇到的问题
- 新闻客户端04 - 请求网络数据
- [易语言]计次循环首/判断循环首/循环判断首
- spring 动态数据源切换实例
- tensorflow实现基于CNN残差网络的一个简化版YOLO
- 13.spring与struts整合
- Drawable URL
- UVA 624 CD (01背包+打印路径)
- 在java中,如何将方法作为参数传递
- yyyymmddhhmmss时间戳转为Date以及对指定时间偏移N个小时(分、天..)后的日期
- DFS CodeForces 510B (Fox And Two Dots)
- js基础5
- 玩转tomcat多个部署及改名
- 教你如何在windows与linux系统中设置MySQL数据库名、表名大小写敏感