MyEclipse6.5下struts2+spring2+hibernate3 整合

MyEclipse6.5下struts2+spring2+hibernate3 整合

今天开始正式学习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 如果能够正确地显示“这是一个测试”就表示大功告成了,接下来就可以做一些实际的工作了。 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/110452.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • kitti数据集介绍_cifar10数据集下载

    kitti数据集介绍_cifar10数据集下载KITTI数据集下载及解析版本更新时间更新内容作者1V1.0xxx完成主体内容W.Xiao2文章目录KITTIDataset1简介1.1数据采集平台1.2坐标系2数据解析2.1image文件2.2velodyne文件2.3calib文件2.4label文件3KITTI可视…

    2022年10月10日
    0
  • AllinOne安装OpenStack

    AllinOne安装OpenStack1.虚拟机的配置准备内存:8G+CPU:2|2网络设置:NAT硬盘设置:100G+2.启动虚拟机3.网络配置vi/etc/sysconfig/network添加内容:NETWORKING=yes

    2022年10月25日
    0
  • Python3.7 环境下安装wxPython教程

    Python3.7 环境下安装wxPython教程python3.7环境下安装wxPython教程我的环境安装步骤运行代码和结果我的环境我的安装环境:系统:Windows10专业版;Python版本:Python3.7;wxpython版本::wxPython4.0.6;安装步骤下载wxpython安装包确定你的Python版本,比如我这里是Python3.7,到官网https://pypi.org/proj…

    2022年5月11日
    40
  • ConcurrentHashMap1.8 – 扩容详解「建议收藏」

    ConcurrentHashMap1.8 – 扩容详解「建议收藏」简介ConcurrenHashMap在扩容过程中主要使用sizeCtl和transferIndex这两个属性来协调多线程之间的并发操作,并且在扩容过程中大部分数据依旧可以做到访问不阻塞,具体是如何实现的,请继续。说明:该源码来自于jdk_1.8.0_162版本。特别说明:不想看源码可直接跳到后面直接看图解。一、sizeCtl属性…

    2022年6月24日
    24
  • Linux top 命令详解

    Linux top 命令详解查看多核CPU命令 mpstat-PALL 和  sar-PALL  说明:sar-PALL>aaa.txt  重定向输出内容到文件aaa.txt top命令经常用来监控linux的系统状况,比如cpu、内存的使用,程序员基本都知道这个命令,但比较奇怪的是能用好它的人却很少,例如top监控视图中内存数值的含义就有不少的曲解。本文

    2022年9月24日
    0
  • linux修改密码报错_linux修改其他用户密码

    linux修改密码报错_linux修改其他用户密码第一种:/usr/bin/passwd的权限中没有添加s即SUID特殊权限即:-rwxr-xr-x.1rootroot270008月222010/usr/bin/passwd解决方案:chmodu+s/usr/bin/passwdSUID的功能简单的说就是让组用户或其他用户在执行该文件是拥有文件所有者(own)权限,这里就是需要获取w(写)权限,这样才能将新密码写到/etc…

    2022年9月5日
    1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号