`
siemenew
  • 浏览: 6498 次
  • 性别: Icon_minigender_1
  • 来自: 嘉兴
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

MyEclipse6.5下struts2+spring2+hibernate3 整合

阅读更多
欢迎转载,但是必须保留"2009年6月25日 by 虚拟猪"这一行



    今天开始正式学习ssh开发了,想用ssh框架开发当然先的搭建开发平台,我用的相关软件版本如下:

1、MyEclipse6.5

2、struts2.0.11.2,现在官方网站上的最高版本为Struts2.1.6,我之所以没有用最新版本是因为最新版本在网上的资料少一些,万一出问题解决起来有难度,网上能够咨询的地方也不多。下面的版本没有用最新也是基于这个道理。下载地址:http://www.apache.org

3、spring2.5.5,最新版为2.5.6,下载地址为http://www.springsource.org/download

4、hibernate3.2 最新版为3.3.2,下载地址为https://www.hibernate.org

     软件准备好了就可以开始搭建环境了,由于是新学习,因此没有使用myeclipse提供的自动引入spring和hibernate支持。

1、在myeclipse6.5下新建一个web project项目

2、先来引入struts2的支持:把下载回来的struts2的压缩包解开,把解压目录下lib目录下的struts-core-2.0.11.2.jar,xwork-2.0.5.jar,freemarker-2.3.8.jar,ognl-2.6.11.jar,struts2-spring-plugin-2.0.11.2.jar五个jar文件拷贝到刚才新建项目的WebRoot\WEB-INF\lib目录下。

3、引入spring2支持:把spring解压目录下dist下的spring.jar拷贝到WebRoot\WEB-INF\lib目录下

4、hibernate3支持:把hibernate解压目录下的hibernate3.jar复制到WebRoot\WEB-INF\lib目录下。

5、一些基础支持的引入:如日志、数据库驱动(我用的是mysql数据库,所以引入的是mysql数据库支持包)、连接池、以及一些基础的公用的支持包,这些包都能在struts2、spring、hibernate解压目录下找到,有些包三个目录下都有,我一般找版本比较高的。具体的包名如下:c3p0-0.9.1.2.jar , dom4j-1.6.1.jar , commons-collection.jar , commons-dbcp.jar , commons-io.jar, commons-pool.jar, jta.jar , cglib-nodep-2.1.3.jar , mysql-connector-java-5.0.8.jar , commons-logging.jar.

注:以上只是必须基础的包,真正开发不会只有这些包,我的原则是需要了再加,而不是一开始把所有的包都放进去.

     接下来要做的是配置工作了

1、配置web.xml,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">
<!-- 配置struts2的拦截器(过滤器) -->
  <filter>
       <filter-name>struts2</filter-name>
       <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>

<filter-mapping>
      <filter-name>struts2</filter-name>
       <url-pattern>/*</url-pattern>
</filter-mapping>


<!--配置spring的监听器-->
<listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>


2、在src目录下建立struts.xml,也可直接从其他地方复制一个。内容如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<!--指定字符集-->

<constant name="struts.i18n.encoding" value="UTF-8"></constant>

<package name="struts2" extends="struts-default">



<!--这个action用于测试配置是否正确,没有实际用处-->
     <action name="testAction" class="testAction">

            <result name="success">/test.jsp</result>

     </action>

</package>
</struts>



3、配置applicationContext.xml,在WEB-INF下建立此文件,或从其他地方复制,内容如下

<?xml version="1.0" encoding="UTF-8"?>
<!--
  - Middle tier application context definition for the image database.
  -->
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
<!-- (in this case, JDBC-related settings for the dataSource definition below) -->

<bean id="testAction" class="com.test.action.Test">

</bean>
</beans>



4、在scr目录下建立com.test.action包并在该包下建立Test.java,内容如下

package com.test.action;

import com.opensymphony.xwork2.ActionSupport;

public class Test extends ActionSupport {
@Override
public String execute() throws Exception {
  return SUCCESS;
}

}

5、在webroot目录下建立test.jsp文件,内容如下:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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>My JSP 'test.jsp' starting page</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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
  </head>
 
  <body>
   这是一个测试 <br>
  </body>
</html>


5、配置tomcat在tomcat的server.xml的host标签内加入  <Context path="/test" docBase="D:\test\WebRoot"  reloadable="true" />



6、在myeclipse 中启动tomcat后在浏览器地址栏中输入http://localhost:8080/test/testAction.action 如果能够正确地显示“这是一个测试”就表示大功告成了,接下来就可以做一些实际的工作了。


2009年6月25日 by 虚拟猪


欢迎转载,但是必须保留"2009年6月25日 by 虚拟猪"这一行

1
1
分享到:
评论

相关推荐

    struts2+spring+hibernate Demo

    用MyEclipse 6.5搭建struts2+spring+hibernate老有问题,现有MyEclipse 8.5搭建,没问题了, hibernate配置了自动创建表,只要创建数据库就可以运行了

    myeclipse6.5整合ssh实例

    一个自己写的使用myeclipse6.5整合struts1.2+spring2.5+hibernate3.2的实例,没有包含库文件,太大了csdn不让上传;还有一篇pdf的文档,希望大家喜欢,我的blog上有这篇文章,地址:http://blog.csdn.net/hua_wei

    Myeclipse6.5GA__struts1.2_spring2.5_hibernate3.2

    对于JAVA学习者来说,这是一篇非常有价值的资料,充分利用此资源能够有效地学习SSH框架以及SSH框架的工作机制,少走弯路。 Myeclipse6.5+struts1.2+spring2.5+hibernate3.2整合实例(非常详细)

    Myeclipse6.5GA struts1.2 spring2.5 hibernate3.2 整合实例(非常详细).docx

    Myeclipse + struts1.2 + spring + hibernate3.2 整合实例,本文档非常详细地说明了如何将以上四者整合起来,希望对大家有帮助!

    struts+hibernate+spring整合注册登陆源码

    源代码,自己写的,用的myeclipse6.5+mysql,数据库自己建。

    Struts2+Hibernate3.2+Spring2.0 SSH整合小实例(经典)

    本程序是一个完整的ssh框架整合的项目,实现了基本的增、删、查、改功能,还是现了xls(excel)表格的生成和输入输出支持下载。还是用了简单的表单验证。...SSH版本Struts2+Hibernate3.2+Spring2.0。

    struts+spring+hibernate(三大框架),外加ajax

    这是一个结合三大框架,外加ajax做的一个详细的例子,里面分包很明确,很容易懂! 由于工程的大小问题,没有考包。(我用的MyEclipse6.5 ,倒的都是最高版本的)。

    struts2+hibernate3.2+spring2.5集成方案

    通过阅读该文档,您能轻松的完成在MyEclipse6.5和Tomcat6.0下完成Struts2+Hibernate3.2+Sprint2.5的整合

    SSH集成搭建视频(struts+spring+hibernate)

    我录制的视频,用的是myeclipse6.5+tomcat6.0+sql2000 我把ssh的一部分jar包打进去了 大家可以自己搭建,由于源工程太大了,所以只有这小部分包,望多提宝贵意见~

    SSH,struts1.2+hibernate3.2+spring2.5,缺的包

    SSH,struts1.2+hibernate3.2+spring2.5,缺的包,myeclipse6.5集成后,去掉asm-2.2.3包,加上这几个就好,解决“sessionfactory”无法创建问题

    ssh1+mysql+myeclipse6.5

    在网上看了好多教程,结果配下来都有问题,到处下的尴尬,今天终于把它给整好了,一个简单的SSH1框架,STRUTS1.2+SPRING2.0+HIBERNATE集成一个简单的框架,因为是在TOMCAT里面布置的,原来的框架JAR包还是要按照他们的说明...

    基于(Struts2+Hibernate3.1+Spring2.5)实现的blog管理系统

    此系统为博客管理系统,为培训过程中所完成的Demo,系统基于HIberinate3+Sping2.5+Struts2实现。。完成了国际化。 开发环境为MyEclipse6.5+JDK1.6, 系统所有的数据库为:mysql5.0 数据库名为:myblog(请手工建此...

    structs2_spring_heibernate用户列表管理

    编译环境:MyEclipse6.5+Tomcate5.5+SQL Server 2000 简介: 该系统主要利用struts2+spring+hibernate框架实现了数据库的增加、删除和修改功能。 部署:数据库使用附加数据库的方式部署。

    struts1,hibernate,spring整合demo1

    采用struts1,hibernate,spring整合并分页demo,并作事物管理,数据库采用MySQL,数据可用test内方法生成。采用myeclipse6.5开发

    客户管理系统CRM-13

    开发环境:myEclipse6.5 + jdk1.6 + tomcat...struts1.x + spring 2.x + hibernate 3.x 使用了SSH框架 + DWR + Json 演示地址:http://foart.cn:8080/crm 用户信息: id userName userPW userRole state version

    CRM最新最全的源码包含数据库-11

    struts1.x + spring 2.x + hibernate 3.x 客户关系管理系统(crm),源码(含数据库),Struts+Spring+Hibernate开发,包括营销管理、客户管理、服务管理、统计报表、基础数据和权限管理六个模块,带需求文档及数据库...

    myeclipse 插件热部署 jrebel6.5

    myeclipse 插件热部署 jrebel6.5 亲测可用,资源下载到磁盘,然后打开myeclipse 路径为:Windows ---&gt; Perferences --&gt; MyEclipse --&gt;Servers --&gt;Tomcat --&gt; Tomcat 7.x --&gt;JDK 配置jvm参数: -...

    北大青鸟客户管理系统

    开发环境:myEclipse6.5 + jdk1.6 + tomcat...struts1.x + spring 2.x + hibernate 3.x 使用了SSH框架 + DWR + Json 演示地址:http://foart.cn:8080/crm 用户信息: id userName userPW userRole state version

    Struts2、Hibernate3、Spring的简单配置与使用.doc

    Struts2、Hibernate3、Spring的简单配置与使用 对于SSH框架的初学者很有帮助,是本人亲自一步一步部署起来的。使用MyEclipse6.5工具。...包括Struts2、Hibernate3、Spring使用,以及他们之间的整合。

Global site tag (gtag.js) - Google Analytics