1.首先用Eclipse创建一个web项目(Eclipse EE 版)

new->Other->

输入web 然后选择Dynamic Web Project->next->

输入项目名(这里新建一个项目名叫ssh)

->Next->next

->finish

接下来就是导入我们所需的jar包

先导入strus2的jar包

然后修改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" version="3.0">
<display-name>ssh</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>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>
<!-- 配置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>
</web-app>
加入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>
<constant name="struts.objectFactory" value="spring" /> <package name="default" namespace="/" extends="json-default">
<!--
<default-action-ref name="index" /> <global-exception-mappings>
<exception-mapping result="error" exception="java.lang.Exception" />
</global-exception-mappings> <action name="error">
<result>error.jsp</result>
</action>
<action name="login" class="com.accp.actions.UserAction" method="login">
<result name="teacher">/WEB-INF/content/Teacher/main.jsp</result>
<result name="student">/WEB-INF/content/Student/main.jsp</result>
<result name="admin">/WEB-INF/content/Admin/main.jsp</result>
<result name="input">/login.jsp</result>
</action> <action name="register" class="com.accp.actions.UserAction" method="register">
<result name="success">/login.jsp</result>
<result name="input">/register.jsp</result>
</action>
</package> </struts>

接着导入spring的jar包

由于spring和struts2整合还要加入

struts2-spring-plugin-2.3.15.jar

接着还是修改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" version="3.0">
<display-name>ssh</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>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>
<!-- 配置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容器spring配置文件的位置 -->
<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>
</web-app>

增加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: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-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/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"
>
<context:annotation-config />
<context:component-scan base-package="com.accp" /> <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/exam"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
<property name="maxActive" value="40" />
<property name="maxIdle" value="10" />
<property name="maxWait" value="10000" />
</bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="annotatedClasses">
<list>
<value>com.entities.User</value>
<value>com.entities.Subject</value>
<value>com.entities.Answer</value>
<value>com.entities.Category</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<!-- <prop key="hibernate.current_session_context_class">thread</prop> -->
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <tx:advice id="txAdvice" transaction-manager="txManager" >
<tx:attributes>
<!-- <tx:method name="get*" read-only= "true" /> -->
<tx:method name="*"
rollback-for="HibernateException"
propagation="REQUIRED"
/>
</tx:attributes>
</tx:advice> <aop:config>
<aop:pointcut id="serviceMethods"
expression="execution(public * com.accp.biz..*.*(..))"/>
<aop:advisor pointcut-ref="serviceMethods" advice-ref="txAdvice"/>
</aop:config>
</beans>

然后加入hibernate所需的hibernate3.jar和必须jar包如下:

javassist-3.12.0.GA.jar这个jar包不用加,前面加过

如果要用的注解的话还要导入hibernate-jpa-2.0-api-1.0.0.Final.jar

因为要用到连接池和数据库所以还要导入commons-pool-1.6.jar和commons-dbcp-1.4.jar

还有数据库驱动mysql-connector-java-5.1.18-bin.jar我用的是mysql

然后启动项目

发现有点问题还要加入aopalliance-1.0.jar和aspectjweaver.jar,因为项目可能要用到ajax所以还要加入struts2-json-plugin-2.3.7.jar

呵呵成功了!里面有些配置文件相信能看懂吧。。。

ssh 框架整合试例 (spring+struts2+hibernate)的更多相关文章

  1. Eclipse下面的Maven管理的SSH框架整合(Struts,Spring,Hibernate)

    搭建的环境:eclispe下面的maven web项目 Struts:    2.5.10 Spring:    4.3.8 Hibernate:   5.1.7 .Final MySQL:   5. ...

  2. SSH框架整合 日志处理Spring结合 log4j、slf4j

    1. 加入log4j和slf4j的jar包 2. web.xml: <context-param> <!--log4j配置地址 --> <param-name>lo ...

  3. ssh框架整合其他方式(没有hibernate核心配置文件)

  4. J2EE SSH框架整合教程

    本文仅作为学习和研究的参考,与实际项目使用技术有所不同,由于作者水平有限,错误疏漏在所难免,请各位看官批评指教. 项目的源代码放在:https://github.com/Frank-Pei/SSHIn ...

  5. SSH(Spring Struts2 Hibernate)框架整合(注解版)

    案例描述:使用SSH整合框架实现部门的添加功能 工程: Maven 数据库:Oracle 框架:Spring Struts2  Hibernate 案例架构: 1.依赖jar包 pom.xml < ...

  6. Spring+Hibernate+Struts(SSH)框架整合

    SSH框架整合 前言:有人说,现在还是流行主流框架,SSM都出来很久了,更不要说SSH.我不以为然.现在许多公司所用的老项目还是ssh,如果改成流行框架,需要成本.比如金融IT这一块,数据库dao层还 ...

  7. [Java web]Spring+Struts2+Hibernate整合过程

    摘要 最近一直在折腾java web相关内容,这里就把最近学习的spring+struts2+hibernate进行一个整合,也就是大家经常说的ssh. 环境 工具IDE :Idea 2018 数据库 ...

  8. Spring+Struts2+Hibernate的整合

    这篇主要采用Maven搭建Spring+Struts2+Hibernate的整合项目,复习一下SSH框架,虽然spring提供自己的MVC框架, 但是Spring也提供和其他框架的无缝整合,采用组件形 ...

  9. 简单Spring+Struts2+Hibernate框架搭建

    使用Maven+Spring+Struts2+Hibernate整合 pom文件 <project xmlns="http://maven.apache.org/POM/4.0.0&q ...

随机推荐

  1. [原创] - C#编程大幅提高OUTLOOK的邮件搜索能力!

    使用OUTLOOK, 你有没有遇到过上图的问题? 多达18419封邮件! 太多了, 每次想找一个邮件都非常耗时, 想办法解决这个问题成了一件非常紧迫的事情. 利用MS Search当然可以, 但是它太 ...

  2. shell动态解析sql的binlog

    #!/usr/bin #设置数据库连接 conn='mysql -hhost -Pport -uusername -ppassword' #获取最新的binlog文件 logfile=$($conn ...

  3. poj 1236 Network of Schools(强连通、缩点、出入度)

    题意:给出一个有向图.1:问至少选出多少个点,才能沿有向边遍历所有节点.2:问至少加多少条有向边,使原图强连通. 分析:第一个问题,缩点后找所有树根(入度为0).第二个问题,分别找出入度为0和出度为0 ...

  4. *ecsho 的商品详细页面上获取该商品的一级分类ID及NAME

    1.打开goods.php并找到 $smarty->assign('goods', $goods); 在它上面增加以下代码 $cat_arr = get_parent_cats($goods[' ...

  5. (六)6.8 Neurons Networks implements of PCA ZCA and whitening

    PCA 给定一组二维数据,每列十一组样本,共45个样本点 -6.7644914e-01  -6.3089308e-01  -4.8915202e-01 ... -4.4722050e-01  -7.4 ...

  6. 重拾Excel之为什么

    现在如今想想自己,已经有许久许久没有充过电了.现在想好好地充电. 机遇总是垂青于有准备的人!

  7. 两天三场Java实习生面试总结

    Java 关键字(如abstract)[详解] String[相关面试题] String.StringBuffer.StringBuilder区别 String中有没有使一个字符串反转的方法 线程的实 ...

  8. 两个异步处理AsyncTask和Handler的优缺点

    AsyncTask和Handler对比 1 ) AsyncTask实现的原理,和适用的优缺点 AsyncTask,是android提供的轻量级的异步类,可以直接继承AsyncTask,在类中实现异步操 ...

  9. 用vs2012的命令利用xsd文件生成对应的C#类,把xml的string类型映射到生成的类

    输入命令: xsd d:\TDDOWNLOAD\atom-author-link.xsd /c /language:C# /outputdir:d:\ 含义: 将d:\TDDOWNLOAD\atom- ...

  10. 折腾了半天,终于搞定了apache的rewrite功能

    基本步骤和网上其它文章说得基本一样.只是在具体操作的时候或多或少存在些问题 一 打开 apache 的配置文件 httpd.conf . 二 将#loadmodule rewrite_module m ...