Java ssh

来源:互联网 发布:即时通讯源码 编辑:程序博客网 时间:2024/06/06 01:08

Java的SSH的框架整合

写了好多篇的Android的代码了,在写几篇关于Java的的,博客园里肯定都是Java的的前辈啊,写的不好多给意见。

SSH,什么是SSH呢,Struts的+ Spring + Hibernate的,这三个就是整个的SSH了。

集成SSH框架的系统从职责上分为四层:表示层,业务逻辑层,数据持久层和域模块层,以帮助开发人员在短期内搭建结构清晰,可复用性好,维护方便的网络应用程序。其中使用的Struts作为系统的整体基础架构,负责MVC的分离,在Struts的框架的模型部分,控制业务跳转,利用Hibernate的框架对持久层提供支持,春季做管理,管理支柱和休眠。具体做法是:用面向对象的分析方法根据需求提出一些模型,将这些模型实现为基本的Java对象,然后编写基本的DAO(Data Access Objects)接口,并给出Hibernate的DAO实现,采用Hibernate架构实现的DAO类来实现的Java类与数据库之间的转换和访问,最后由spring做管理,管理支柱和休眠

Jar包的链接:链接:http://pan.baidu.com/s/1gfv7EYB密码:qrpf
如果链接失效了,发我的邮箱,我给你们发送dingchao7323@qq.com

需要的瓶子包:

首先看配置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“    xsi:schemaLocation =“http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd        http://www.springframework.org/schema/aop    http://www.springframework.org/schema/aop/spring-aop-3.1.xsd        http://www.springframework.org/schema/tx    http://www.springframework.org/schema/tx/spring-tx.xsd“ >    <! - Spring和Hibernate的整合分为两种        第一种:加载整个休眠配置文件        第二种:首先配置数据与然后配置会话工厂    - >     <! - 这个是需要hibernate.cfg.xml文件- >     <! - 第一种配置:加载整个hibernate配置文件1    <bean id =“sessionFactory”class =“org.springframework.orm.hibernate3.LocalSessionFactoryBean”>        <property name =“configLocation”value =“classpath:hibernate.cfg.xml”> </ property>    </豆>     - >      <! - =========================================== ===第一种方式=========================================== ========== - >      <! - 第二种不要sessionFactory 2 2 - >      < bean id =“dataSource” class =“org.apache.commons.dbcp.BasicDataSource” >          < property 命名= “URL” = “JDBC:预言:瘦:@localhost:1521:****” > </ 属性>          < 属性= “driverClassName” = “oracle.jdbc.OracleDriver” > </ 属性>          < 属性= “username”的= “****” > </ 属性>          < 属性= “密码” 的值= “****” > </ 属性>      </ >      <! - 加载数据库连接2 - >      < bean id =“sessionFactory” class =“org.springframework.orm.hibernate3.LocalSessionFactoryBean” >          < property name =“dataSource” ref =“dataSource” > </ property >          <! - 加载实体类配置文件- >          <! - 加载工具例如show_sql - >          < property name =“hibernateProperties” >              < props >                  < prop key =“hibernate.dialect” > org.hibernate.dialect.Oracle9Dialect </ prop >                  < prop key =“hibernate.show_sql” > true </ prop >                  < prop key =“hib ernate.format_sql“ > true </ prop >              </ props >          </ property >          <! - 加载实体类配置文件- >          <! - 第二种的另外另一种配置实体类方式1这一个是找的具体的***。hbm.xml文件- >          <! - <property name =“mappingResources”>             <列表>                 <值> COM / DC /实体/ Dept.hbm.xml </值>                 <值> COM / DC /实体/ Emp.hbm.xml </值>             </列表>         </属性> - >          <! - 第二种的另外另种配置实体类方式2这个是找的所在的包- >       < 属性= “mappingDirectoryLocations” >              < 列表>                  < >类路径:COM / dc / entity / </ value >              </ list >          </ property >       </ bean >       <! - ========================= =====================第二种方式========================= ============================ - >          <! - 只是上边不一样,这俩个都有- >     <! - hibernateTemplate - >     < bean id =“hibernateTemplate” class =“org.springframework.orm.hibernate3.HibernateTemplate” >         < property name = “sessionFactory” ref =“sessionFactory” > </ property >     </ bean >        <! - ============================ Dao的配置=============== ============= - >     < bean id =“empDao” class =“com.dc.dao.impl.SaleOrderLineDaoImpl” >         < property name =“hibernateTemplate” ref =“hibernateTemplate” > </ property >     </ bean >                 <! - SaleOrderDaoImpl - >     < bean id =“SaleOrderDao” class =“com.dc.dao.impl.SaleOrderDaoImpl” >         < property name =“hibernateTemplate” ref =“hibernateTemplate” > </ property >     </ bean >        <! - ============================服务的配置=============== ============= - >     < bean id =“empService” class =“com.dc.service.impl.SaleOrderLineServiceImpl” >         < property name =“soldao” ref =“empDao” > </ property >     </ bean >             <! - SaleOrderServiceImpl - >     < bean id =“SaleOrderService” class =“com.dc.service.impl.SaleOrderServiceImpl” >         < property name =“sodao” ref =“SaleOrderDao” > </ property >     </ bean >        <! - ============================动作的配置=============== ============= - >     < bean id =“empAction” class =“com.dc.action.SaleOrderLineAction” >         < property name =“solSer” ref =“empService” > < 属性>     </ bean >         < bean id =“getInfoById” class =“com.dc.action.SaleOrderLineAction” >         < property name =“solSer” ref =“empService” />     </ bean >                < bean id =“getMaxOdrId” class =“com.dc.action.SaleOrderAction” >             < property name =“soSer” ref =“SaleOrderService” > </ property >         </ bean >         < bean id =“addSaleOrder” class =“ com.dc.action.SaleOrderAction“ >             < property name =”soSer“ ref =”SaleOrderService“ > </ property >         </ bean >        <! - ==============================================配置事物管理器============================================== ======= - >     <! - 配置事务管理器- >     < bean id =“txTran” class =“org.springframework.orm.hibernate3.HibernateTransactionManager” >         < property name =“sessionFactory” ref =“sessionFactory” > </ property >     </ bean >     <! - 声明式事物- >     <! - <tx:method name =“”只读=“false”propagation =“REQUIRED” tx:method> read-only查询时使用传播修改时使用- >     < tx:advice id =“txAdvice” transaction-manager =“txTran” >         < tx:attributes >             < tx:method name =“save *” propagation =“REQUIRED” />             < tx:method name =“insert *” propagation =“REQUIRED” />             < tx:method name =“add *” propagation =“REQUIRED” />             < tx:method name =“up *” 传播= “要求” />             < TX:方法名称= “DL *” 传播= “要求” />             <! - 下面的是查询的- >             < TX:方法名称= “得到*” 只读= “true” />             < tx:method name =“find *” read-only =“true” />             < tx:method name =“ser *” read-only =“true” />             < t x:方法名称=“load *” 只读=“true” />                    </ tx:attributes >     </ tx:advice >        <! -   - >     < AOP:配置>         < AOP:切入点表达式= “执行(。* com.dc.dao * *(..))” ID = “切入点” />         < AOP:顾问advice- ref =“txAdvice” pointcut-ref =“pointcut” />     </ aop:config >        </ beans >
复制代码

struts.xml中的配置

复制代码
<?xml version =“1.0”encoding =“UTF-8” ?> <!DOCTYPE struts PUBLIC    “ -  // Apache软件基金会// DTD Struts配置2.3 // EN”    “http://struts.apache.org/dtds/struts-2.3.dtd” > < struts >    <! - 该属性设置Struts 2是否支持动态方法调用,该属性的默认值为true。如果需要关闭动态方法调用,则可设置该属性为false - >     < constant name =“struts.enable。 DynamicMethodInvocation” = “真”  />     <! - 该属性设置Struts 2的应用是否使用开发模式如果设置该属性为真,则可以在应用出错时显示更多,更友好的出错提示该属性只接受真和FLASE两个值,该属性的默认值是假通常,应用在开发阶段,将该属性设置为真,当进入产品发布阶段后,则该属性设置为假。- >     < 常数=“struts.devMode” value =“true”  />     < constant name =“struts.i18n.encoding” value =“UTF-8”  />     < constant name =“struts.configuration.xml.reload” value =“true “  />     < 常数=” strus.objectFactory” = “弹簧” > </ 恒定>     < 名称= “默认”的命名空间= “/” 延伸= “支柱默认” >        < action name =“show” class =“empAction” >             < result name =“success” > findAllSaleOrderLine.jsp </ result >         </ action >         <! - <action name =“getSaleOrderLineInfoByoolId”class =“com.dc。 action.SaleOrderLineAction”            method =“getInfoById”> <result name =“success”> getSaleOrderLineInfoByoolId.jsp </ result>             </ action> - >        <! - 不建议使用这个,配合上边的常量- >         < action name =“getSaleOrderLineInfoByoolId” class =“getInfoById”             method =“getInfoById” >             < result name =“success” > getSaleOrderLineInfoByoolId.jsp </ result >         < / action >        < action name =“getMaxOdrId” class =“getMaxOdrId” method =“getMaxOdrId” >             < result name =“success” > addSaleOrder.jsp </ result >         </ action >        < action name =“addSaleOrder” class =“addSaleOrder” method =“addSaleOrder” >             < result name =“success” type =“redirectAction” > show </ result >             < result name =“error” type =“redirectAction” > getMaxOdrId </ result >             <! - <result name =“input”> index.jsp </ result> - >         </ action >     </ package ></ struts >
复制代码

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“     xsi:schemaLocation =”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd “     ID =” WebApp_ID” 版本= “3.0” >     < 显示名称> Spring_04_Sale </ 显示名称>     < 欢迎文件列表>         < 欢迎文件>的index.html </ 欢迎文件>         < 欢迎文件> index.htm </ welcome-file >         < welcome-file > index.jsp </ welcome-file >         < welcome-file > default.html </ welcome-file >         < welcome-file > default.htm </ welcome-file >         < welcome-file > default.jsp </ welcome-file >     </ welcome-file-list >     < context-param >         < param-name > contextConfigLocation </ param-name >         < param-value > classpath:applicationContext.xml </ param-value >     </ context-param >    < listener >         < listener-class > org.springframework.web.context.ContextLoaderListener </ listener-class >     </ listener >     < filter >         < filter-name > OpenSessionInViewFilter </ filter-name >         < filter-class > org.springframework .orm.hibernate3.support.OpenSessionInViewFilter </ filter-class >     </ filter >     < filter-mapping >         < filter-name > OpenSessionInViewFilter </ filter-name >         < url-pattern > * .action </ url-pattern >     < / filter-mapping >     < filter >         < filter-name > struts2 </ filter-name >         < filter-class > org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </ filter-class >     </ filter >     < filter -mapping >         < 滤波器名> struts2的</ 过滤器名称>         < URL模式> * .action </ URL模式>     </ 过滤映射>     < 滤波器>         < 滤波器名> EncodingFilter </ 过滤名>         < 滤波器级> com.dc.util.EncodingFilter </ 滤波器级>     </ 过滤器>     < 滤波器映射>         < 滤波器名> EncodingFilter </ 过滤名称>         < URL模式> / * </ URL- pattern >     </ filter-mapping > </ web-app >