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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>Struts2Test</display-name> <!-- --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <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> <!-- 配置欢迎页 --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
applicationContext.xml 放在WEB-INF目录下
<?xml version="1.0" encoding="UTF-8"?> <!--DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"--> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd "> <!-- 使用 annotation 自动注册bean,并检查@Controller, @Service, @Repository注解已被注入,也可以分开注释,或者固定某个目录下 --> <context:component-scan base-package="*" /> </beans>
struts2配置 放在scr目录下
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>Struts2Test</display-name> <!-- --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <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> <!-- 配置欢迎页 --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
action写法 目录:src.com.action
package com.action; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.ExceptionMapping; import org.apache.struts2.convention.annotation.ExceptionMappings; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import org.apache.struts2.convention.annotation.ParentPackage; import org.springframework.beans.factory.annotation.Autowired; import com.opensymphony.xwork2.ActionSupport; import com.service.PersonService; @Namespace("/person") //访问路径的包名 @Results( { @Result(name = "success", location = "/index.jsp"), @Result(name = "error", location = "/hello.jsp") }) @ExceptionMappings( { @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") }) public class PersonAction extends ActionSupport { @Autowired private transient PersonService personService; public PersonAction() { // TODO Auto-generated constructor stub } @Action("login") //访问路径的action名, 想要访问selUser 这个方法 地址为 http://localhost:8080/工程名/yang/login public String selUser(){ System.out.println("login-index"); personService.selPerson(); return SUCCESS; } }
dao 写法 目录:src.com.dao.impl 接口在 src.com.dao 此处略
package com.dao.impl; import org.springframework.stereotype.Repository; import com.dao.PersonDao; @Repository("personDao") public class PersonDaoImpl implements PersonDao { public PersonDaoImpl() { // TODO Auto-generated constructor stub } @Override public void selPerson() { // TODO Auto-generated method stub System.out.println("运行dao"); } }
service 写法 目录:src.com.service.impl,接口在 src.com.service 此处略
package com.service.impl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.dao.PersonDao; import com.service.PersonService; @Service("personService") public class PersonServiceImpl implements PersonService { @Autowired private transient PersonDao personDao ;//注入的DAO public PersonServiceImpl() { // TODO Auto-generated constructor stub } @Override public void selPerson() { // TODO Auto-generated method stub System.out.println("运行service"); personDao.selPerson(); } }
注意增加这个jar包 其他spring包,struts包自备
struts2-spring-plugin-2.3.16.jar
来自:http://my.oschina.net/UpBoy/blog/194437
http://www.open-open.com/lib/view/open1390793407836.html
相关推荐
Struts2+hibernate+spring开发,使用MySQL数据,实现学生基本信息的增删改查功能,但是页面不美观
struts2+Spring3.0+Mybatis组合框架开发,可以正常的运行,其中使用spring注解方式管理action
Struts2+spring注解配置 很好哦
struts2+mybatis+spring 注解 很好的例子 。看了都说好!
Struts2+Spring3+Hibernate4+Maven+EasyUI整合入门视频012,
基于注解的Spring+Struts2+Mybatis+Maven项目,Spring 3.0 Struts2 Mybatis3.0
SSH三大框架整合 struts2+hibernate+spring (全注解方式进行配置)
Struts2+spring注解配置简介.ppt
全注解,演示Struts2 + Spring + MyBatis整合,开发环境为Eclipse,数据库为mysql。
struts2+spring2.5+hibernate3.2 + freemarker 全新功能实现的增删改查+freemarker 摸版 struts2 的方式自己去看简单。 spring2.5 是用注释来注入 hibernate3.2 是用ejb3注解映射关系 hibernate3 +个属性可以自动...
Struts2.3.28+spring4.1.6+hibernate4.3.8整合总结(注解),测试环境使用myeclipse2014,jdk1.6
Struts+Spring+Mybatis+EasyUI(jQuery)注解案例。采用注解的方式跟踪代码依赖性,实现替代配置文件功能。里面包含了平时用的增删改查及分页,分页查询时用的是存储过程,提高了数据库的性能。代码简单、易懂。
(1)该项目是基于spring3+struts2+hibernate3+spring security3的权限管理项目 (2)后台我已经实现了权限管理,包括用户,角色和资源的分配。前台实现了spring security3的管理 (3)网上案例普遍是后台单一登陆。...
超级详细的SSH2项目实例详解,并且附带两个项目详解。两种注解实现方式。...在JavaEE企业级开发中,以SSH2框架为核心的应用非常广,大象根据项目实践经验,通过二个实例,详细的为大家讲解如何实现全注解式的开发。
2.Action里通过struts2-spring-plugin.jar插件自动根据名字注入。 3.Ajax无刷新异步调用Struts2,返回Json数据,以用户注册为例。 4.在服务端分页查询功能,优点:实时性:跳页才查询。数据量小:只加载当前页的记录...
struts2+HIbernate+Spring整合所需jar包 包含数据库连接池jar包 hibernate注解所需jar包 日志处理log4j及slf日志框架及实现的jar包
整合S2SH+Freemarker+oscache,后台用Spring管理各个bean,Hibernate做数据库持久化,viewer用Freemarker。整合中对Struts2,Hibernate,Spring都采用Annotation进行注解类。
struts2+spring+hibernate s2sh半注解结合方式框架搭建开发