最近向自己单独做一个基于ssh的项目,来预习和巩固自己的Java基础。找了一个实际生活中的定做衣服的例子来做一做,放到博客上给大家一起分享学习,后边会持续更新项目编写时候遇到的困难和使用的技术等。

1.点击新建--》选择Dynamic Web Project --》next--》next。。并创建package结果图:

2.创建自己的架包库并导入架包到项目:

平时开发需要使用外部的jar时直接将其拷入WEB-INF/lib下。这个是可以的,但是分类一下会让系统更有条理。eclipse中分类是以uesr Libary为单位的,创建user Libary的方法很简单,Window--> Preference---> Java --->Build Path ---> User Library 。点击右侧的 New 就可以创建一个 User library, 选择 Add External jars就可以添加我们要的jar文件了。

引入 user library : myEclipse下可以很方便的引入,直接右击项目名 选择building path 再选择子菜单就可以了,但是eclipse中没有。eclipse的方法也不难。右击项目名,选择building path 在选择 configure building path,在弹出的窗体上部选中 Libraries,右侧选择 Add Library,在弹框中选择 User Library,点下一步就可以看到自己添加的User Library了。

我们可以发现 WEB-INF/lib是空的,但是 Libraries下都了一个文件夹,是不是感觉项目更有序了?

但是运行是会抛出 java.lang.ClassNotFoundException 错误,因为这个只是逻辑上的引入,我们可以选中项目,右击Properties 选择 Deployment Assembly,点击 Add,弹框Java Build Path Entities,按提示操作,问题就迎刃而解了。

Java build path时的图。这里我整理好了ssh三个框架所要使用的jar包,放在了lljf_ssh_jar  User Library里

下图是添加ssh使用的jar包和创建所要使用类包后的项目结构图:

***********需要注意的是SSH项目整合起来时一定要注意各个框架之间的版本兼容问题,很多时候错误出现的问题可能是框架版本之间的不兼容问题导致的。本项目使用的是Struts2 2.3 + Spring 3.2 + Hibernate 3.6***********

3.编辑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">
<display-name>lljf</display-name> <!-- struts2配置 -->
<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> <!-- spring配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:bean.xml</param-value>
<!-- <param-value>/WEB-INF/classes/applicationContext.xml</param-value> -->
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

4.创建并编辑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>
<package name="com.lljf" extends="struts-default" namespace="/" >
<!-- 交给Spring管理,能够实现AOP处理,建议使用:就是class中使用spring中的id名称即可 -->
<action name="order" class="orderAction" method="orderAdd">
<result name="add">lljfList.jsp</result>
</action>
</package>
</struts>

5.创建并编辑Spring配置文件

<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 所有配置的公用部分 -->
<!-- 1.配置c3p0数据库连接池实例 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl"></property>
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="user" value="lljf"></property>
<property name="password" value="123456"></property>
<property name="initialPoolSize" value="2"></property>
<property name="maxPoolSize" value="6"></property>
</bean>
<!-- 2.SessionFactory实例创建 -->
<!-- 所有的配置都由spring维护(项目中不需要hibernate.cfg.xml了) -->
<bean id ="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- a.注入连接池 -->
<property name="dataSource" ref="dataSource"></property>
<!-- b.hibernate常用配置 :方言,显示sql,自动建表 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!-- c.映射文件路径配置 -->
<property name="mappingLocations">
<list>
<value>classpath:com/lljf/vo/*.hbm.xml</value>
</list>
</property>
</bean>
<!-- 3.事务配置 -->
<!-- a.事务管理器 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- b.事务增强 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="*" read-only="false"/>
</tx:attributes>
</tx:advice>
<!-- c.AOP配置 = 切入点表达式(拦截目标对象,生成代理) + 事务增强应用-->
<aop:config>
<aop:pointcut expression="execution(* com.lljf.service.*.*(..))" id="pt"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pt"/>
</aop:config> <!-- 配置Action,DAO,Service类 -->
<!-- 配置Action的类,其中scope是指action中的orderService变量是多例模式 -->
<bean id="orderAction" class="com.lljf.action.OrderAction" scope="prototype">
<!-- 注入业务层的类 -->
<property name="orderService" ref="orderService"></property>
</bean> <!-- 配置Service层的类 -->
<bean id="orderService" class="com.lljf.service.impl.OrderServiceImpl">
<!-- 注入DAO层的类 -->
<property name="orderDao" ref="orderDao"></property>
<property name="customerDao" ref="customerDao"></property>
</bean> <!-- 配置Dao层的类 -->
<bean id="orderDao" class="com.lljf.dao.impl.OrderDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="customerDao" class="com.lljf.dao.impl.CustomerDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>

今天先到这了,敬请关注后续更新。

使用eclipse整合ssh项目的例子--lljf(1)的更多相关文章

  1. 转载:eclipse 搭建SSH项目(第二篇,有具体的项目例子)

    原文地址:http://blog.csdn.net/yeohcooller/article/details/9316923 读博文前应该注意: 本文提纲:本文通过一个用户注册的实例讲解SSH的整合.创 ...

  2. 转载:eclipse 搭建SSH项目(第一篇)

    第一篇:原文地址:http://blog.csdn.net/aaaaaaaa0705/article/details/6288431(虽然没有具体的例子,不过逻辑性强点,比较容易看懂) SSH框架是最 ...

  3. 使用CXF做webservice整合现有项目的例子

    从网上看了很多CXF的资料,大部分都是单独的作为一个webservice项目,对于在现有的spring项目上提供webservice服务的例子基本没有找到. 我做的这个例子是介绍怎么把cxf整合到现有 ...

  4. SSH项目整合教学Eclipse搭建SSH(Struts2+Spring3+Hibernate3)

    这篇博文的目的 尝试搭建一个完整的SSH框架项目. 给以后的自己,也给别人一个参考. 读博文前应该注意: 本文提纲:本文通过一个用户注册的实例讲解SSH的整合.创建Struts项目,整合Hiberna ...

  5. eclipse 创建maven 项目 动态web工程完整示例 maven 整合springmvc整合mybatis

    接上一篇: eclipse 创建maven 项目 动态web工程完整示例 eclipse maven工程自动添加依赖设置 maven工程可以在线搜索依赖的jar包,还是非常方便的 但是有的时候可能还需 ...

  6. spring学习(四) ———— 整合web项目(SSH)

    清楚了spring的IOC 和 AOP,最后一篇就来整合SSH框架把,记录下来,以后应该会用的到. --WH 一.web项目中如何使用spring? 当tomcat启动时,就应该加载spring的配置 ...

  7. spring(四) 手动整合web项目(SSH)

    清楚了spring的IOC 和 AOP,最后一篇就来整合SSH框架把,记录下来,以后应该会用的到. --WH 一.web项目中如何使用spring? 当tomcat启动时,就应该加载spring的配置 ...

  8. Maven项目整合SSH框架

    ---------------------siwuxie095                                         Maven 项目整合 SSH 框架         创建 ...

  9. SSH项目整合基本步骤

    SSH项目整合基本步骤 一.项目简介 该项目是由Spring4.Struts2 以及 Hibernate4 整合搭建的 web 项目,把Action分开编写,便于查看,使用JSTL.EL标签. 二.项 ...

随机推荐

  1. The frequent used operation in Linux system

    The frequently used operation in Linux system    2017-04-08 12:48:09  1. mount the hard disk:  #: fd ...

  2. Windoes包管理工具(Scoop)

    Windoes包管理工具(Scoop) 对于习惯了apt-get,brew等工具的开发者来说,Windows下配置环境相对繁琐,这里推荐Win下的包管理工具Scoop. Win 包管理工具 Choco ...

  3. DTS(待了解)

    DTS(待了解)  vs trasaction事务 脏数据 && 脏数据的清理 永远返回非空对象(忌:返回空值) 异常: invoker(trackTrace:debug.releas ...

  4. SQL Server同一表不同列数据同步

    直接上脚本 update table set a=b where a=xxx table==表名称 a==需要同步的列 b==数据源列,就是a列要的数据是b列的数据 where 条件.不加where则 ...

  5. js var 以及 let 的差异

    例子 window.checklist=[{"boardname":"motor_board","cur":"1.0.0" ...

  6. Git Learning3 Eclipse Tools(未完成)

    1.创建Git 操作:工程 右键 Team Share Project Git 完成创建 2.全局设置:Window->Preference->Git->Configuration- ...

  7. Dart学习-操作符

    dart定义了下表所示的运算符.你可以重写许多这些运算符. 描述 运算符 一元后缀 expr++ expr-- () [] . ?. 一元前缀 -expr !expr ~expr ++expr --e ...

  8. Vue组件通信

    单向数据流通信 单向数据流通信是指父组件传递数据给子组件,子组件是不可以修改该数据的(可以改,但会警告) 父组件通过自定义属性传递数据给子组件,子组件使用props接收 如果想修改数据,子组件需要使用 ...

  9. 20190411wdVBA_排版

    Sub LayoutForExamPaper() Dim StartTime As Variant Dim UsedTime As Variant StartTime = VBA.Timer Appl ...

  10. tensorflow lite的demo在android studio上环境搭建

    由于很久没有接触过Android开发,而且最早用的是eclipse,所以这个demo在android studio上的搭建过程,真的是踩了不少坑.记录这篇文章,纯粹是给自己一点收获. 环境搭建的过程, ...