• struts2+hibernate整合


    1.准备好struts2+hibernate所需要的包。

     

     

    2.myeclispe中,window->preferences->

    3.

    在web.xml中配置好Struts2框架的核心控制器

    <?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></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>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>
    

      

    struts.xml文件

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <!DOCTYPE struts PUBLIC
     3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
     4     "http://struts.apache.org/dtds/struts-2.3.dtd">
     5 
     6 <struts>
     7     <constant name="struts.devMode" value="true"></constant>
     8     <package name="p1" extends="struts-default">
     9         
    10     </package>
    11 </struts>

    hibernate.cfg.xml文件

    <?xml version='1.0' encoding='utf-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
            "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
            "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
    <session-factory>
    	<property name="dialect">
    		org.hibernate.dialect.MySQLDialect
    	</property>
    	<property name="hbm2ddl.auto">update</property>
    	<property name="show_sql">true</property>
    	<property name="current_session_context_class">thread</property>
    	<property name="format_sql">true</property>
    	<property name="myeclipse.connection.profile">mysql</property>
    
    
    	<property name="connection.driver_class">
    		com.mysql.jdbc.Driver
    	</property>
    	<property name="connection.username">root</property>
    	<property name="connection.password">1996</property>
    	<property name="connection.url">
    		jdbc:mysql://localhost:3306/diylife?useUnicode=true&characterEncoding=UTF-8
    	</property>
    
    
    	<property name="cache.provider_class">
    		org.hibernate.cache.EhCacheProvider
    	</property>
    	<property name="cache.use_second_level_cache">true</property>
    	<property name="generate_statistics">true</property>
    	<property name="cache.use_query_cache">true</property><!-- 开启查询缓存 -->
    	
    </session-factory>
    </hibernate-configuration>
    

    然后基本环境搭建完成了,当我在tomcat8.0上装载完项目,启动tomcat是报错如下:

    Struts2配置问题java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

    解决办法:方法一:右键点击项目--->build path-->configure build path-->左侧菜单栏就会看到Deployment Assembly-->右侧点击add按钮--->选择java build path entries--->next--->选择项目--->finish.

    重新装载下项目,重启下tomcat,就不报错了。

      

  • 相关阅读:
    消息队列非阻塞
    外挂简介
    mfc小工具开发之定时闹钟之---二十四小时时区和时间段
    mfc小工具开发之定时闹钟之---时间获取和音频播放
    mfc小工具开发之定时闹钟之---多线程急线程同步
    mfc小工具开发之定时闹钟之---功能介绍
    8127 timeout!!! 搞死人啊
    RGB565 转换 BMP24
    linux 格式化u盘
    linq分页扩展(转)
  • 原文地址:https://www.cnblogs.com/ting1996/p/8075837.html
Copyright © 2020-2023  润新知