zoukankan      html  css  js  c++  java
  • 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,就不报错了。

      

  • 相关阅读:
    万亿养老市场如何抢占商机?云巢智慧康养物联网加速器,三招化解ISV痛点!
    13个VSCode使用技巧,开启高效的开发模式
    添零占位 —— 快速生成N个0的六种办法
    使用 dumi 打包 React 组件库并生成文档站点
    Transformer架构记录(四)
    Transformer架构记录(三)
    Transformer架构记录(二)
    Transformer架构记录(一)
    NLP预训练发展小结二(Bert之后)
    p3c 插件,是怎么检查出你那屎山的代码?
  • 原文地址:https://www.cnblogs.com/ting1996/p/8075837.html
Copyright © 2011-2022 走看看