返回:[web工程]Struts2+Spring3.1+Hibernate3.6的集成
上一步:[web工程]集成struts2 mvc
下一步:[web工程]集成hibernate
集成spring3
- 复制jar到WEB-INF/lib目录:
复制,并添加到java build path:
org.springframework.aop-3.1.0.M1.jar
org.springframework.asm-3.1.0.M1.jar
org.springframework.beans-3.1.0.M1.jar
org.springframework.context-3.1.0.M1.jar
org.springframework.core-3.1.0.M1.jar
org.springframework.expression-3.1.0.M1.jar
org.springframework.web-3.1.0.M1.jar
spring包分类总结:
============================================
spring3 lib:
core:
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.expression-3.0.5.RELEASE.jar
core depend lib:
org.springframework.asm-3.0.5.RELEASE.jar
web:
tld: spring.tld, spring-form.tld
org.springframework.web-3.0.5.RELEASE.jar
springMVC: org.springframework.web.servlet-3.0.5.RELEASE.jar
db:
org.springframework.orm-3.0.2.RELEASE.jar
org.springframework.transaction-3.0.2.RELEASE.jar
org.springframework.jdbc-3.0.2.RELEASE.jar
aop:
org.springframework.aop-3.0.5.RELEASE.jar
depend on:
aopalliance-1.0.jar
============================================
- 配置applicationContext.xml,并配置LoginAction的bean
- 普通bean配置,注意加上scope="prototype"
-
注解方式配置:<context:component-scan base-package="org.skzr.demo"/>
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" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="loginAction" class="org.skzr.demo.action.LoginAction" scope="prototype"/>
<context:component-scan base-package="org.skzr.demo"/>
</beans>
添加注解到LoginAction.java,注意:@Component("loginActionComponent") @Scope("prototype")
/**
* Copyright (c) 2010-2020 by wasion.com
* All rights reserved.
* @author <a href="mailto:skzr.org@gmail.com">skzr.org</a>
* @date 2011-5-19 下午10:20:57
*/
package org.skzr.demo.action;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.opensymphony.xwork2.ActionSupport;
/**
* 登录检测
* @author <a href="mailto:skzr.org@gmail.com">skzr.org</a>
* @version 1.0.0
* @since JDK1.6
*/
@Component("loginActionComponent")
@Scope("prototype")
public class LoginAction extends ActionSupport {
private static final long serialVersionUID = 1L;
/** 用户名 */
private String userName;
/** 密码 */
private String password;
/**
* @return {@link #userName}
*/
public String getUserName() {
return userName;
}
/**
* @param userName {@link #userName}
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* @return {@link #password}
*/
public String getPassword() {
return password;
}
/**
* @param password {@link #password}
*/
public void setPassword(String password) {
this.password = password;
}
/**
* 登录验证
* @return 验证后页面视图
*/
public String check() {
return "admin".equals(userName) ? "welcome" : "success";
}
}
- 修改web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<description>我爱编程</description>
<display-name>我爱编程</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>app.root</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>10000</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<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>
<init-param>
<param-name>config</param-name>
<param-value>struts-default.xml,struts-plugin.xml,struts.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
- 启动web查看后台输出是不是正常初始化spring
- 修改struts.xml的action从spring中获取
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="demo" extends="struts-default" namespace="/">
<action name="loginAction" class="org.skzr.demo.action.LoginAction">
<result>/WEB-INF/jsp/login.jsp</result>
<result name="welcome">/WEB-INF/jsp/welcome.jsp</result>
</action>
<!-- 来自spring配置的bean -->
<action name="loginActionSpring" class="loginAction">
<result>/WEB-INF/jsp/login.jsp</result>
<result name="welcome">/WEB-INF/jsp/welcome.jsp</result>
</action>
<!-- 来自spring注解配置的bean -->
<action name="loginActionSpringComponent" class="loginActionComponent">
<result>/WEB-INF/jsp/login.jsp</result>
<result name="welcome">/WEB-INF/jsp/welcome.jsp</result>
</action>
</package>
</struts>
- 哈哈struts运行不正常了,无法使用spring的:
- 修改struts.properties添加spring支持:struts.objectFactory=spring
- 复制struts2-spring-plugin-2.2.3.jar到lib,并添加到java build path
- 重新运行系统即可正常登录了。
新的登录页面login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>系统登录:</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<center><h1>struts action</h1></center>
<form action="loginAction!check.do" method="post">
<table align="center">
<tr><td>用户名:</td><td><input name="userName" value="${userName }"></td></tr>
<tr><td>密 码:</td><td><input name="password" type="password"></td></tr>
<tr><td><input type="submit" value="登录"></td><td><input type="reset" value="重置"></td></tr>
</table>
</form>
<center><h1>action配置在spring中的</h1></center>
<form action="loginActionSpring!check.do" method="post">
<table align="center">
<tr><td>用户名:</td><td><input name="userName" value="${userName }"></td></tr>
<tr><td>密 码:</td><td><input name="password" type="password"></td></tr>
<tr><td><input type="submit" value="登录"></td><td><input type="reset" value="重置"></td></tr>
</table>
</form>
<center><h1>action配置在spring中的(注解方式配置)</h1></center>
<form action="loginActionSpringComponent!check.do" method="post">
<table align="center">
<tr><td>用户名:</td><td><input name="userName" value="${userName }"></td></tr>
<tr><td>密 码:</td><td><input name="password" type="password"></td></tr>
<tr><td><input type="submit" value="登录"></td><td><input type="reset" value="重置"></td></tr>
</table>
</form>
</body>
</html>
- 下载demo程序 Good luck ^ ^
返回:[web工程]Struts2+Spring3.1+Hibernate3.6的集成
上一步:[web工程]集成struts2 mvc
下一步:[web工程]集成hibernate
分享到:
相关推荐
在Web项目中集成Spring,在Web项目中集成Spring,在Web项目中集成Spring
spring mq集成 web工程发送和接收消息例子 亲自测试可以用 代码机构清晰 需要自行安装mq服务端
前者是构建在Spring框架上的Web应用程序框架,可以同许多其他视图技术无缝集成;后者是控制业务处理流程的有效解决方案,提供了一种编写有状态和基于会话的Web应用程序的简便手段。 《深入解析Spring MVCgn Web Flow...
xfire集成了spring的jar包,放到工程中引用即可用xfire集成spring的方式进行webservice接口开发
3、Maven的Web工程集成Spring4 1、使用Eclipse搭建Maven的Web工程 请参考:Eclipse中使用Maven创建基本的web项目 2、Maven的Web工程集成Spring4MVC 请参考:Maven的Web工程集成Spring4 昨晚太晚就没完成这一篇,今天...
使用spring集成cxf,在两个web project里发布及调用webservice server端使用spring+springmvc+mybatis+cxf,client端使用struts2+spring+hibernate+cxf 两个工程均为myeclipse project,包含所有除myeclipse自带以外...
2.web工程的web.xml中配置CXFServlet <!-- 设置Spring容器加载配置文件路径 --> <param-name>contextConfigLocation <param-value>classpath*:applicationContext-server.xml <listener-class>org....
这是一个JAVA web工程,解压后可直接导入到ECLIPSE中,部署到tomcat中后可以直接运行; 里面有两个定时任务, 一个是使用普通JAVA类,通过Spring使用MethodInvokingJobDetailFactoryBean注入,形式调用; 另一个...
这是一个基于b/s模式的spring web工程代码生产工具.附有一视频例子。 <br>支持bean定义配置,web配置,java源代码生成,dao,service,mvc各个层次集成的配置以及相关页面的生产。 <br>涉及技术:spring mvc,...
基于spring mvc的Excelweb的报表项目,使用spring data jpa、spring security、spring mvc搭建工程 特有的EXCEL+绑定数据列的报表设计方式,行列对称,能够轻松处理复杂的报表展现样式,部署方式简单而灵活,具有...
《Spring3.x企业应用开发实战》是在《精通Spring2.x——企业应用开发详解》的基础上,经过历时一年的重大调整改版而成的,本书延续了上一版本追求深度,注重原理,不停留在技术表面的写作风格,力求使读者在熟练...
office在线编辑ONLYOFFICE集成java和前端office在线编辑ONLYOFFICE集成java和前端office在线编辑ONLYOFFICE集成java和前端office在线编辑ONLYOFFICE集成java和前端office在线编辑ONLYOFFICE集成java和前端
对Spring与Hibernate进行了整合,在eclipse下创建一个示例性的Dynamic Web Project. 源码包含库文件。
maven集成的ssm项目,mybatis-plus是集成了mybatis所有的数据在自己封装出自己的方法,非常好用。
Json-RPC 和Spring MVC 的集成实现,有一登录的例子。文件是一个Eclipse的动态web工程。直接导入eclipse就可以发布了。Tomcat需要5.5以上版本。
使用axis2与spring3进行集成,实现的webservice服务。 资料为myeclipse下的web工程,可解压后直接导入。 发布到tomcat6下运行。
SSM集成rabbitmq的web工程,这个文件是初始的web项目,下载后可以用来练习。具体的配置,请参考本人的博客
Jboss7上+maven搭建struts2+spring3+hibernate3完整能运行工程源码,在tomcat7上运行也成功测试了,注意:我工程文件是用myeclipse2013开发的,你需要导入自己ide的时候,会有兼容性问题:最好阁下是自己新建一个maven...
3,struts版本:struts-2.3.16.1 spring版本:spring-framework-4.0.3.RELEASE hibernate版本:hibernate-release-4.3.4.Final 4,集成了编码过滤器和压缩过滤器,拿来就可以直接在上面建新工程。