基于SSH框架的小型论坛项目  

  一、项目入门  传送门

  二、框架整合  传送门

  三、用户模块  传送门

  四、页面显示  传送门

  五、帖子模块  传送门

  六、点赞模块  传送门

  七、辅助模块  传送门

导入Jar包

  导入完别忘了Add Path

  查看Eclipse IDE中导入的Jar包

  Gary_SSHForum->Build Path->Configure Build Path

  

添加xml配置文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop.xsd
  13. http://www.springframework.org/schema/tx
  14. http://www.springframework.org/schema/tx/spring-tx.xsd">
  15.  
  16. </beans>

applicationContext.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE hibernate-configuration PUBLIC
  3. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  4. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

hibernate.cfg.xml

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

struts.xml

 整合Spring与Struts

  1. <!-- 让spring随着Web项目的启动而启动 -->
  2. <listener>
  3. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  4. </listener>
  5.  
  6. <!-- 读取配置文件 -->
  7. <context-param>
  8. <param-name>contextConfigLocation</param-name>
  9. <param-value>classpath:applicationContext.xml</param-value>
  10. </context-param>
  11.  
  12. <!-- 扩大session的范围 -->
  13. <filter>
  14. <filter-name>openSession</filter-name>
  15. <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
  16. </filter>
  17. <filter-mapping>
  18. <filter-name>openSession</filter-name>
  19. <url-pattern>/*</url-pattern>
  20. </filter-mapping>
  21.  
  22. <!-- 让struts启动 -->
  23. <filter>
  24. <filter-name>struts</filter-name>
  25. <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
  26. </filter>
  27. <filter-mapping>
  28. <filter-name>struts</filter-name>
  29. <url-pattern>/*</url-pattern>
  30. </filter-mapping>
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  5. id="WebApp_ID" version="3.1">
  6. <display-name>Gary_SSHForum</display-name>
  7. <welcome-file-list>
  8. <welcome-file>index.html</welcome-file>
  9. <welcome-file>index.htm</welcome-file>
  10. <welcome-file>index.jsp</welcome-file>
  11. <welcome-file>default.html</welcome-file>
  12. <welcome-file>default.htm</welcome-file>
  13. <welcome-file>default.jsp</welcome-file>
  14. </welcome-file-list>
  15.  
  16. <!-- 让spring随着Web项目的启动而启动 -->
  17. <listener>
  18. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  19. </listener>
  20.  
  21. <!-- 读取配置文件 -->
  22. <context-param>
  23. <param-name>contextConfigLocation</param-name>
  24. <param-value>classpath:applicationContext.xml</param-value>
  25. </context-param>
  26.  
  27. <!-- 扩大session的范围 -->
  28. <filter>
  29. <filter-name>openSession</filter-name>
  30. <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
  31. </filter>
  32. <filter-mapping>
  33. <filter-name>openSession</filter-name>
  34. <url-pattern>/*</url-pattern>
  35. </filter-mapping>
  36.  
  37. <!-- 让struts启动 -->
  38. <filter>
  39. <filter-name>struts</filter-name>
  40. <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
  41. </filter>
  42. <filter-mapping>
  43. <filter-name>struts</filter-name>
  44. <url-pattern>/*</url-pattern>
  45. </filter-mapping>
  46.  
  47. </web-app>

web.xml

整合Spring与Hibernate

  MySQL中添加数据库

  1. <!-- 配置数据源 -->
  2. <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  3. <property name ="jdbcUrl" value="jdbc:mysqL:///garyssh_forum"></property>
  4. <property name ="driverClass" value="com.mysql.jdbc.Driver"></property>
  5. <property name ="user" value="root"></property>
  6. <property name ="password" value="123456"></property>
  7. </bean>
  8.  
  9. <!-- 配置sessionFactory -->
  10. <bean name = "sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  11. <property name="dataSource" ref="dataSource"></property>
  12. <property name="hibernateProperties">
  13. <props>
  14. <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
  15. <prop key="hibernate.hbm2ddl.auto">update</prop>
  16. <prop key="hibernate.show_sqp">true</prop>
  17. <prop key="hibernate.format_sql">true</prop>
  18. </props>
  19. </property>
  20.  
  21. <property name="mappingDirectoryLocations" value="classpath:com/Gary/domain"></property>
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop.xsd
  13. http://www.springframework.org/schema/tx
  14. http://www.springframework.org/schema/tx/spring-tx.xsd">
  15.  
  16. <!-- 配置数据源 -->
  17. <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  18. <property name ="jdbcUrl" value="jdbc:mysqL:///garyssh_forum"></property>
  19. <property name ="driverClass" value="com.mysql.jdbc.Driver"></property>
  20. <property name ="user" value="root"></property>
  21. <property name ="password" value="123456"></property>
  22. </bean>
  23.  
  24. <!-- 配置sessionFactory -->
  25. <bean name = "sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  26. <property name="dataSource" ref="dataSource"></property>
  27. <property name="hibernateProperties">
  28. <props>
  29. <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
  30. <prop key="hibernate.hbm2ddl.auto">update</prop>
  31. <prop key="hibernate.show_sqp">true</prop>
  32. <prop key="hibernate.format_sql">true</prop>
  33. </props>
  34. </property>
  35.  
  36. <property name="mappingDirectoryLocations" value="classpath:com/Gary/domain"></property>
  37.  
  38. </bean>
  39.  
  40. </beans>

applicationContext.xml

整合Spring与Hibernate配置事务

  1. <!-- 配置事务的核心管理器 -->
  2. <bean name="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  3. <property name="sessionFactory" ref="sessionFactory"></property>
  4. </bean>
  5.  
  6. <!-- 通知 -->
  7. <tx:advice id="advice" transaction-manager="transactionManager">
  8. <tx:attributes>
  9. <tx:method name="*"/>
  10. </tx:attributes>
  11. </tx:advice>
  12.  
  13. <!-- 织入 -->
  14. <aop:config>
  15. <!-- 切入点 -->
  16. <aop:pointcut expression="execution(* com.Gary.service.*.*(..))" id="pc"/>
  17. <!-- 配置切面 切入点+通知 -->
  18. <aop:advisor advice-ref="advice" pointcut-ref="pc"/>
  19. </aop:config>
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop.xsd
  13. http://www.springframework.org/schema/tx
  14. http://www.springframework.org/schema/tx/spring-tx.xsd">
  15.  
  16. <!-- 配置数据源 -->
  17. <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  18. <property name ="jdbcUrl" value="jdbc:mysqL:///garyssh_forum"></property>
  19. <property name ="driverClass" value="com.mysql.jdbc.Driver"></property>
  20. <property name ="user" value="root"></property>
  21. <property name ="password" value="123456"></property>
  22. </bean>
  23.  
  24. <!-- 配置sessionFactory -->
  25. <bean name = "sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  26. <property name="dataSource" ref="dataSource"></property>
  27. <property name="hibernateProperties">
  28. <props>
  29. <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
  30. <prop key="hibernate.hbm2ddl.auto">update</prop>
  31. <prop key="hibernate.show_sqp">true</prop>
  32. <prop key="hibernate.format_sql">true</prop>
  33. </props>
  34. </property>
  35.  
  36. <property name="mappingDirectoryLocations" value="classpath:com/Gary/domain"></property>
  37.  
  38. </bean>
  39.  
  40. <!-- 配置事务的核心管理器 -->
  41. <bean name="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  42. <property name="sessionFactory" ref="sessionFactory"></property>
  43. </bean>
  44.  
  45. <!-- 通知 -->
  46. <tx:advice id="advice" transaction-manager="transactionManager">
  47. <tx:attributes>
  48. <tx:method name="*"/>
  49. </tx:attributes>
  50. </tx:advice>
  51.  
  52. <!-- 织入 -->
  53. <aop:config>
  54. <!-- 切入点 -->
  55. <aop:pointcut expression="execution(* com.Gary.service.*.*(..))" id="pc"/>
  56. <!-- 配置切面 切入点+通知 -->
  57. <aop:advisor advice-ref="advice" pointcut-ref="pc"/>
  58. </aop:config>
  59.  
  60. </beans>

applicationContext.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  5. id="WebApp_ID" version="3.1">
  6. <display-name>Gary_SSHForum</display-name>
  7. <welcome-file-list>
  8. <welcome-file>index.html</welcome-file>
  9. <welcome-file>index.htm</welcome-file>
  10. <welcome-file>index.jsp</welcome-file>
  11. <welcome-file>default.html</welcome-file>
  12. <welcome-file>default.htm</welcome-file>
  13. <welcome-file>default.jsp</welcome-file>
  14. </welcome-file-list>
  15.  
  16. <!-- 让spring随着Web项目的启动而启动 -->
  17. <listener>
  18. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  19. </listener>
  20.  
  21. <!-- 读取配置文件 -->
  22. <context-param>
  23. <param-name>contextConfigLocation</param-name>
  24. <param-value>classpath:applicationContext.xml</param-value>
  25. </context-param>
  26.  
  27. <!-- 扩大session的范围 -->
  28. <filter>
  29. <filter-name>openSession</filter-name>
  30. <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
  31. </filter>
  32. <filter-mapping>
  33. <filter-name>openSession</filter-name>
  34. <url-pattern>/*</url-pattern>
  35. </filter-mapping>
  36.  
  37. <!-- 让struts启动 -->
  38. <filter>
  39. <filter-name>struts</filter-name>
  40. <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
  41. </filter>
  42. <filter-mapping>
  43. <filter-name>struts</filter-name>
  44. <url-pattern>/*</url-pattern>
  45. </filter-mapping>
  46.  
  47. </web-app>

web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xmlns:aop="http://www.springframework.org/schema/aop"
  6. xmlns:tx="http://www.springframework.org/schema/tx"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop.xsd
  13. http://www.springframework.org/schema/tx
  14. http://www.springframework.org/schema/tx/spring-tx.xsd">
  15.  
  16. <!-- 配置数据源 -->
  17. <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  18. <property name ="jdbcUrl" value="jdbc:mysqL:///garyssh_forum"></property>
  19. <property name ="driverClass" value="com.mysql.jdbc.Driver"></property>
  20. <property name ="user" value="root"></property>
  21. <property name ="password" value="123456"></property>
  22. </bean>
  23.  
  24. <!-- 配置sessionFactory -->
  25. <bean name = "sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
  26. <property name="dataSource" ref="dataSource"></property>
  27. <property name="hibernateProperties">
  28. <props>
  29. <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
  30. <prop key="hibernate.hbm2ddl.auto">update</prop>
  31. <prop key="hibernate.show_sqp">true</prop>
  32. <prop key="hibernate.format_sql">true</prop>
  33. </props>
  34. </property>
  35.  
  36. <property name="mappingDirectoryLocations" value="classpath:com/Gary/domain"></property>
  37.  
  38. </bean>
  39.  
  40. <!-- 配置事务的核心管理器 -->
  41. <bean name="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  42. <property name="sessionFactory" ref="sessionFactory"></property>
  43. </bean>
  44.  
  45. <!-- 通知 -->
  46. <tx:advice id="advice" transaction-manager="transactionManager">
  47. <tx:attributes>
  48. <tx:method name="*"/>
  49. </tx:attributes>
  50. </tx:advice>
  51.  
  52. <!-- 织入 -->
  53. <aop:config>
  54. <!-- 切入点 -->
  55. <aop:pointcut expression="execution(* com.Gary.service.*.*(..))" id="pc"/>
  56. <!-- 配置切面 切入点+通知 -->
  57. <aop:advisor advice-ref="advice" pointcut-ref="pc"/>
  58. </aop:config>
  59.  
  60. </beans>

applicationContext.xml

项目过程中的问题 

一、ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...

  Log4j2:用于输出日志

  出现文件提前结束:xml的问题

  struts添加了约束  必须要有<struts>  </struts>

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE struts PUBLIC
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
  4. "http://struts.apache.org/dtds/struts-2.5.dtd">
  5.  
  6. <struts>
  7.  
  8. </struts>

二、Tomcat启动超时问题Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds  传送门

  

  把tomcat启动时间适当延长:

  

  打开tomcat设置页,修改启动时间:

  

  经上一步如果还是启动超时的话,可以对项目进行clean,它的作用是将工程中的.class文件全部删除,同时重新编译工程:

  

  

  然后再次重新部署tomcat,启动即可

  一、项目入门  传送门

  二、框架整合  传送门

  三、用户模块  传送门

  四、页面显示  传送门

  五、帖子模块  传送门

  六、点赞模块  传送门

  七、辅助模块  传送门

JavaWeb_(SSH论坛)_二、框架整合的更多相关文章

  1. JavaWeb_(SSH论坛)_一、项目入门

    基于SSH框架的小型论坛项目 一.项目入门 传送门 二.框架整合 传送门 三.用户模块 传送门 四.页面显示 传送门 五.帖子模块 传送门 六.点赞模块 传送门 七.辅助模块 传送门 项目已上传至gi ...

  2. JavaWeb_(SSH论坛)_七、辅助模块

    基于SSH框架的小型论坛项目 一.项目入门 传送门 二.框架整合 传送门 三.用户模块 传送门 四.页面显示 传送门 五.帖子模块 传送门 六.点赞模块 传送门 七.辅助模块 传送门 为避免代码冗余, ...

  3. JavaWeb_(SSH论坛)_六、点赞模块

    基于SSH框架的小型论坛项目 一.项目入门 传送门 二.框架整合 传送门 三.用户模块 传送门 四.页面显示 传送门 五.帖子模块 传送门 六.点赞模块 传送门 七.辅助模块 传送门 联合主键 创建p ...

  4. JavaWeb_(SSH论坛)_五、帖子模块

    基于SSH框架的小型论坛项目 一.项目入门 传送门 二.框架整合 传送门 三.用户模块 传送门 四.页面显示 传送门 五.帖子模块 传送门 六.点赞模块 传送门 七.辅助模块 传送门 回复帖子 分析回 ...

  5. JavaWeb_(SSH论坛)_四、页面显示

    基于SSH框架的小型论坛项目 一.项目入门 传送门 二.框架整合 传送门 三.用户模块 传送门 四.页面显示 传送门 五.帖子模块 传送门 六.点赞模块 传送门 七.辅助模块 传送门 帖子表与回复表 ...

  6. JavaWeb_(SSH论坛)_三、用户模块

    基于SSH框架的小型论坛项目 一.项目入门 传送门 二.框架整合 传送门 三.用户模块 传送门 四.页面显示 传送门 五.帖子模块 传送门 六.点赞模块 传送门 七.辅助模块 传送门 User表 id ...

  7. SSH(Spring SpringMVC Hibernate)框架整合

    项目说明: 使用SSH(Spring SpringMVC Hibernate)框架整合添加部门功能 项目结构   1.导入依赖jar包 <!--单测--> <dependency&g ...

  8. SSH(Spring4+Struts2+Hibernate4)框架整合

    1.加入Spring4 ①. 加入 jar 包

  9. JavaWeb_(Mybatis框架)使用Mybatis对表进行增、删、改、查操作_二

    系列博文: JavaWeb_(Mybatis框架)JDBC操作数据库和Mybatis框架操作数据库区别_一 传送门 JavaWeb_(Mybatis框架)使用Mybatis对表进行增.删.改.查操作_ ...

随机推荐

  1. # 丢包&&掉帧&&文件删除

    丢包&&掉帧&&文件删除 丢包:指一个或多个数据包(packet)的数据无法透过网络到达目的地,丢失一些信息 掉帧:帧数就是在1秒钟时间里传输的图片的量,每一帧都是静止 ...

  2. C++练习 | 单链表的创建与输出(结构体格式)

    #include <iostream> #include <stdio.h> using namespace std; #define OK 1 #define ERROR 0 ...

  3. 03:linux文件操作四剑客

    1.1 find查找命令 1.find命令说明 1. Linux find命令用来在指定目录下查找文件. 2. 任何位于参数之前的字符串都将被视为欲查找的目录名. 3. 如果使用该命令时,不设置任何参 ...

  4. c# 不让窗体显示在alt tab中

    protected override CreateParams CreateParams { get { const int WS_EX_APPWINDOW = 0x40000; const int ...

  5. 12 Python之函数进阶

    1. 动态传参 *, ** : 形参: 聚合 位置参数* -> 元组 def func(*args, a, b, c): print(a, b , c, args) func(1,2,3,4,5 ...

  6. Eclipse中插件的运用

    1. hotcode2.jar 支持java代码热部署,改了本地java代码不需要重新部署生效,可以节省开发时间,提高开发效率. 安装方法: 到help -- install new software ...

  7. CentOS7搭建FastDFS V5.11分布式文件系统(三)

    1.测试 前面两篇博文已对FastDFS的安装和配置,做了比较详细的讲解.FastDFS的基础模块都搭好了,现在开始测试下载. 1.1 配置客户端 同样的,需要修改客户端的配置文件: /etc/fdf ...

  8. shell脚本中的一些特殊符号

    在shell中常用的特殊符号罗列如下:  # ;   ;; . , / \\ 'string'| !   $   ${}   $? $$   $*  \"string\"* **  ...

  9. Ext4文件系统修复

    Ext4文件系统修复 目录 一. super block........................................................................ ...

  10. win 10.0.17134.915 版本无法更新处理方法

    用CMD(以管理员方式运行)分别运行:1. Dism /Online /Cleanup-Image /RestoreHealth2.   sfc /scannow 注意:第2步比较慢,有进度条,请耐心 ...