Spring4学习笔记-Spring4整合Struts2(基于配置文件的方式)
来源:互联网 发布:sql查询分析器下载 编辑:程序博客网 时间:2024/05/22 09:54
Person.java
public class Person {private String username;public void setUsername(String username) {this.username = username;}}
PersonService.java
public class PersonService {public void save() {System.out.println("PersonService save...");}}
PersonAction.java
public class PersonAction {private PersonService personService;public void setPersonService(PersonService personService) {this.personService = personService;}public String execute() {personService.save();return "success";}}
applicationContext.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"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="person" class="com.spring.beans.Person"><property name="username" value="spring"></property></bean><bean id="personService" class="com.spring.services.PersonService"></bean><!-- 注意:在配置IOC容器中配置Struts2的Action时需要配置scope属性,其值必须为prototype --><bean id="personAction" class="com.spring.actions.PersonAction" scope="prototype"><property name="personService" ref="personService"></property></bean></beans>
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> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <!-- Spring整合Struts2时,在Struts2中配置的Spring的Action的class需要只想IOC容器中该bean的id --><action name="personSave" class="personAction"><result>success.jsp</result></action> </package></struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID" version="2.5"><display-name>Spring_08</display-name><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><!-- 配置Spring配置文件的名称和位置 --><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></context-param><!-- 启动IOC容器的ServletContextListner --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- 配置Struts2的filter --><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></web-app>
测试页
<a href="personSave.action">personSave.action</a>
http://yunpan.cn/cgJjBqGcwuevq 提取码 2500
本文出自 “优赛工作室” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/1558569
0 0
- Spring4学习笔记-Spring4整合Struts2(基于配置文件的方式)
- Spring4学习笔记-AOP(基于配置文件的方式)
- Spring4+hiberante5+Struts2.5.13基于配置文件整合
- Spring4学习笔记-声明式事务(基于配置文件的方式)
- Spring4学习笔记-AOP(基于注解的方式)
- J2EE系列之Spring4学习笔记(十三)--Spring4整合Struts2和Hibernate4
- J2EE系列之Spring4学习笔记(十四)--Spring4整合Struts2和Hibernate4
- Spring4学习笔记-Spring4整合Hibernate4
- Spring4 学习笔记(3)-Spring 基于 XML 的方式配置 Bean(供自己学习)
- Spring4 学习笔记(3)-Spring 基于 XML 的方式配置 Bean
- Spring4学习笔记-声明式事务(基于注解的方式)
- Java学习笔记--SSH框架整合(struts2、spring4、hibernate5)
- Spring4+hibernate4+struts2配置文件
- Struts2+Hibernate4+Spring4整合
- Struts2+Spring4+myBatis3整合
- spring4+hibernate4+struts2整合
- Spring4 整合Hibernate4,Struts2
- spring4 hibernate4 struts2 maven的整合
- Spring4学习笔记-AOP(基于注解的方式)
- Spring4学习笔记-AOP(基于配置文件的方式)
- Spring4学习笔记-JDBC
- Spring4学习笔记-声明式事务(基于注解的方式)
- Spring4学习笔记-声明式事务(基于配置文件的方式)
- Spring4学习笔记-Spring4整合Struts2(基于配置文件的方式)
- android selector用法
- Spring4学习笔记-Spring4整合Hibernate4
- Mybatis学习笔记-入门
- Mybatis学习笔记-CURD(基于配置文件的方式)
- Mybatis学习笔记-CURD(基于注解的方式)
- Mybatis学习笔记-一对一关联
- Mybatis学习笔记-一对多关联
- Mybatis学习笔记-动态SQL与模糊查询