SSH(Struts+Spring+Hibernate)三大框架合并工具:MyEclipse 6.0.1+jakarta-tomcat-5.5.91、按这个循序添加3个框架:Struts,Spring,Hibernate
在添加完Struts框架后,写好一些测试代码(方便后面的测试)注意在添加Spring和hibernate的时候最好把那些包都选了,在选择添加包的时候选择Copy那个项在添加Hibernate的时候包的选择一样,在生成applicationContext.xml的时候选择Spring configuration项,接下来选择Exiting Spring configuration项,SessionFactory ID 命名为sf(这个随意)
接下来的是选择数据源ds的配置,选择你配置好的数据源就ok,下一步就是创建一个包来存放HibernateSessionFactory.java
温馨提示:
在执行第二步前,先用MyEclipse Hibernate插件反向生成Entity实体类,Dao类
接着把src下的applicationContext.xml文件copy到WEB-INF目录下(原先的applicationContext.xml不要动,还有用)2、删除2个有问题的包,先找到工程的目录下,找到WEB-INF\lib\,第一个是commons-attributes-compiler.jar,3掉后去这个连接下载修改好的包(http://115.com/file/dptto4fb#commons-attributes-compiler.jar),第二个是asm-2.2.3.jar(搞版本的MyEclipse 可能不需要删除)3、修改web.xml(实现Struts和Spring的整合)下面是修改好的web.xml文件的内容
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <!-- Spring整合 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>4、在applicationContext.xml配置文件中
用设值注入的方式注入dao,biz的实现类
示例:
<bean name="/login" class="com.cus.struts.action.LoginAction">
<property name="loginBizIn" ref="loginBiz"></property>
</bean>
<bean id="loginBiz" class="com.cus.struts.biz.impl.LoginBiz">
<property name="loginDAOIn" ref="LoginDAO"></property>
</bean>
<bean id="LoginDAO" class="com.cus.struts.dao.impl.LoginDAO">
<property name="sessionFactory">
<ref bean="sf" />
</property>
</bean>
温馨提示:<bean name="/login" class="com.cus.struts.action.LoginAction">
name的值是struts-config.xml文件的 path="/login"5、修改struts-config.xml文件的中的type,把type的值改为"org.springframework.web.struts.DelegatingActionProxy">6、修改applicationContext.xml的数据源配置:
下面是修改好的那段代码:class="org.springframework.jdbc.datasource.DriverManagerDataSource"到此SSH的整合差不多了,下面发下完整的工程以及sql代码,数据库是oracle 9i
http://115.com/file/e79xb63p#SSH.rar这个整合还算比较方便的,有更好的求指点啊!
在添加完Struts框架后,写好一些测试代码(方便后面的测试)注意在添加Spring和hibernate的时候最好把那些包都选了,在选择添加包的时候选择Copy那个项在添加Hibernate的时候包的选择一样,在生成applicationContext.xml的时候选择Spring configuration项,接下来选择Exiting Spring configuration项,SessionFactory ID 命名为sf(这个随意)
接下来的是选择数据源ds的配置,选择你配置好的数据源就ok,下一步就是创建一个包来存放HibernateSessionFactory.java
温馨提示:
在执行第二步前,先用MyEclipse Hibernate插件反向生成Entity实体类,Dao类
接着把src下的applicationContext.xml文件copy到WEB-INF目录下(原先的applicationContext.xml不要动,还有用)2、删除2个有问题的包,先找到工程的目录下,找到WEB-INF\lib\,第一个是commons-attributes-compiler.jar,3掉后去这个连接下载修改好的包(http://115.com/file/dptto4fb#commons-attributes-compiler.jar),第二个是asm-2.2.3.jar(搞版本的MyEclipse 可能不需要删除)3、修改web.xml(实现Struts和Spring的整合)下面是修改好的web.xml文件的内容
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <!-- Spring整合 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>4、在applicationContext.xml配置文件中
用设值注入的方式注入dao,biz的实现类
示例:
<bean name="/login" class="com.cus.struts.action.LoginAction">
<property name="loginBizIn" ref="loginBiz"></property>
</bean>
<bean id="loginBiz" class="com.cus.struts.biz.impl.LoginBiz">
<property name="loginDAOIn" ref="LoginDAO"></property>
</bean>
<bean id="LoginDAO" class="com.cus.struts.dao.impl.LoginDAO">
<property name="sessionFactory">
<ref bean="sf" />
</property>
</bean>
温馨提示:<bean name="/login" class="com.cus.struts.action.LoginAction">
name的值是struts-config.xml文件的 path="/login"5、修改struts-config.xml文件的中的type,把type的值改为"org.springframework.web.struts.DelegatingActionProxy">6、修改applicationContext.xml的数据源配置:
下面是修改好的那段代码:class="org.springframework.jdbc.datasource.DriverManagerDataSource"到此SSH的整合差不多了,下面发下完整的工程以及sql代码,数据库是oracle 9i
http://115.com/file/e79xb63p#SSH.rar这个整合还算比较方便的,有更好的求指点啊!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货