- 浏览: 485681 次
- 性别:
- 来自: xiamen
文章分类
最新评论
-
陈乐鹏:
你这个下载要怎么玩?我这里老提示未安装!
[转]使用ScriptX控件进行Web打印总结 -
zqb666kkk:
博主有示例代码吗
cxf ws-security 加密和签名的实现 -
mclin0704:
你好,请问WSDL2Java 可以用java实现吗?
Java2WSDL之java实现 -
hubiao0629:
楼主,这个文件会有不兼容的问题把。
mysql5忘记密码后的处理方法 -
zhaoyubetter:
OK,可以试试!多谢楼主
后台管理界面收集
这三个框架是最流行的框架,这三个版本是比较新的版本,他们的组合是现在做项目完美的解决方案。
纯粹做过备忘录
1、三个框架的结合:
由于spring在内部已经集成了hibernate,所以他俩的组合很容易,基本不用怎么管,只是需要加一些.jar文件,在后面我会说到。而spring和struts的组合稍微麻烦一点,
首先要明白,struts主要解决的是图层方面的功能,所以要在web.xml添加过滤器struts2
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
所有模式为/*的URL都首先经过struts2的处理,
其次,由于要用到spring的IOC所以要添加spring的监听器设置如下:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
默认它会在/WEB-INF下找applicationContext.xml,如果你没有把applicationContext.xml放到这个位置就要在web.xml里设置她的位置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/路径/applicationContext.xml</param-value>
</context-param>
三个框架的结合基本完成了。
2、数据库的配置:
首先在spring的配置文件applicationContext.xml里建立数据源,例如数据库是oracle:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
<property name="username" value="system" />
<property name="password" value="orcl" />
</bean>
其次要配置会话工厂:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect
</prop>
<prop key="hibernate.show_sql">true
</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>facility.DynamicFacilityTable</value>
</list>
</property>
</bean>
由于采用hibernate的注解功能所以用的类为:AnnotationSessionFactoryBean
所以属性annotatedClasses的值直接写实体类(要加上路径),这也比以前要用映射配置文件简单了。
随后配置hibernateTempllate
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
配置好模板后,以后调用的时候直接注入就可以了。在netbeans里有自动生成实体类的功能,如果在数据库里已经建好相应的表,这是很方面的啊O(∩_∩)O。
3、关于编码过滤的配置:
在开发软件的过程中经常出现中文显示乱码问题,为了统一解决,需要在配置里完成相应的设置。
首先,在web.xml里加一个编码过滤器:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
这采用的是spring的编码过滤器,过滤所有url为/*的模式
其次还要在struts.xml里加上:
<constant name="struts.i18n.encoding" value="GBK"/>
这样所有的URL采用的都是GBK编码了,在程序中就不用再为编码问题而头疼了。
最后把完整的配置文件贴出来:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
applicationContex.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:p="http://www.springframework.org/schema/p"
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-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!--bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
/-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
<property name="username" value="system" />
<property name="password" value="****" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect
</prop>
<prop key="hibernate.show_sql">true
</prop>
</props>
</property>
<!-- spring2.5.6 可以直接 整个包搜索读取
<property name="packagesToScan" value="org.eline.entity*.*" /> -->
<property name="annotatedClasses">
<list>
<value>facility.DynamicFacilityTable</value>
</list>
</property>
</bean>
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</beans>
struts.xml 采用netbeans自动生产的就可以:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="example.xml"/>
<!-- Configuration for the default package. -->
<constant name="struts.i18n.encoding" value="GBK"/>
<constant name="struts.objectFactory" value="spring"/>
<package name="default" extends="struts-default">
<action name="login">
<result>success.jsp</result>
</action>
</package>
</struts>
差一点忘了,在netbeans里默认加入spring2.5和struts2的包还不够还要加一下jar文件:
struts2-spring-plugin-2.0.6.jar spring和struts结合的插件
classes12.jar oracle的驱动程序
ejb3-persistence.jar 对实体类进行注解所需的包文件
hibernate-annotations.jar 对hibernate的注解的支持
hibernate-commons-annotations.jar 对hibernate的注解的支持
搞了好长时间才搭好这个框架的集成,中间历尽千辛,个中滋味开发程序的应该都可以理解……
纯粹做过备忘录
1、三个框架的结合:
由于spring在内部已经集成了hibernate,所以他俩的组合很容易,基本不用怎么管,只是需要加一些.jar文件,在后面我会说到。而spring和struts的组合稍微麻烦一点,
首先要明白,struts主要解决的是图层方面的功能,所以要在web.xml添加过滤器struts2
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
所有模式为/*的URL都首先经过struts2的处理,
其次,由于要用到spring的IOC所以要添加spring的监听器设置如下:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
默认它会在/WEB-INF下找applicationContext.xml,如果你没有把applicationContext.xml放到这个位置就要在web.xml里设置她的位置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/路径/applicationContext.xml</param-value>
</context-param>
三个框架的结合基本完成了。
2、数据库的配置:
首先在spring的配置文件applicationContext.xml里建立数据源,例如数据库是oracle:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
<property name="username" value="system" />
<property name="password" value="orcl" />
</bean>
其次要配置会话工厂:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect
</prop>
<prop key="hibernate.show_sql">true
</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>facility.DynamicFacilityTable</value>
</list>
</property>
</bean>
由于采用hibernate的注解功能所以用的类为:AnnotationSessionFactoryBean
所以属性annotatedClasses的值直接写实体类(要加上路径),这也比以前要用映射配置文件简单了。
随后配置hibernateTempllate
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
配置好模板后,以后调用的时候直接注入就可以了。在netbeans里有自动生成实体类的功能,如果在数据库里已经建好相应的表,这是很方面的啊O(∩_∩)O。
3、关于编码过滤的配置:
在开发软件的过程中经常出现中文显示乱码问题,为了统一解决,需要在配置里完成相应的设置。
首先,在web.xml里加一个编码过滤器:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
这采用的是spring的编码过滤器,过滤所有url为/*的模式
其次还要在struts.xml里加上:
<constant name="struts.i18n.encoding" value="GBK"/>
这样所有的URL采用的都是GBK编码了,在程序中就不用再为编码问题而头疼了。
最后把完整的配置文件贴出来:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
applicationContex.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:p="http://www.springframework.org/schema/p"
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-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!--bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
/-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
<property name="username" value="system" />
<property name="password" value="****" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect
</prop>
<prop key="hibernate.show_sql">true
</prop>
</props>
</property>
<!-- spring2.5.6 可以直接 整个包搜索读取
<property name="packagesToScan" value="org.eline.entity*.*" /> -->
<property name="annotatedClasses">
<list>
<value>facility.DynamicFacilityTable</value>
</list>
</property>
</bean>
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</beans>
struts.xml 采用netbeans自动生产的就可以:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="example.xml"/>
<!-- Configuration for the default package. -->
<constant name="struts.i18n.encoding" value="GBK"/>
<constant name="struts.objectFactory" value="spring"/>
<package name="default" extends="struts-default">
<action name="login">
<result>success.jsp</result>
</action>
</package>
</struts>
差一点忘了,在netbeans里默认加入spring2.5和struts2的包还不够还要加一下jar文件:
struts2-spring-plugin-2.0.6.jar spring和struts结合的插件
classes12.jar oracle的驱动程序
ejb3-persistence.jar 对实体类进行注解所需的包文件
hibernate-annotations.jar 对hibernate的注解的支持
hibernate-commons-annotations.jar 对hibernate的注解的支持
搞了好长时间才搭好这个框架的集成,中间历尽千辛,个中滋味开发程序的应该都可以理解……
评论
2 楼
xiaofengtoo
2008-11-30
<!-- annotatedScanPackages可以自动搜索某个package的全部标记@Entity class -->
<property name="annotatedScanPackages">
<list>
<value>com.**.model</value>
</list>
</property>
<property name="annotatedScanPackages">
<list>
<value>com.**.model</value>
</list>
</property>
1 楼
xiaofengtoo
2008-11-30
<!-- annotatedScanPackages可以自动搜索某个package的全部标记@Entity class --> <property name="annotatedScanPackages"> <list> <value>com.company.demo.model</value> </list> </property>
发表评论
-
Mac 安装maven
2017-03-08 23:05 430Mac OS X 安装Maven: 下载 Maven ... -
MAC 安装eclipse svn 插件
2017-03-08 22:48 616参考此链接: http://www.cnblogs.com ... -
tomcat 单机多实例
2015-07-08 09:06 804tomcat 部署单机多实例,实现每个实例都是跟 ... -
java 分块上传
2014-05-30 14:56 1380java 分块下载 java多线程分块上传并 ... -
bat class to java Jad反编译
2013-12-04 14:58 1144反编译所使用的工具是jad.exe 有时候需要批量 ... -
ant svn 自动更新和发布
2012-05-23 16:42 2314团队管理中,当项目非常多,而且发布频繁,手动发布往往非常繁琐, ... -
DatabaseMetaData getExportedKey() 无法获取信息
2012-03-14 17:26 1134在jdbc DatabaseMetaData.getExpo ... -
Column 'IS_AUTOINCREMENT' not found
2012-03-14 10:41 2422java.sql.SQLException: Column ' ... -
java 递归加减法
2012-01-12 17:30 1552有时候设计到list map 做交集,并集等操作。 可以参考 ... -
java 发送mail
2011-12-06 09:19 1485java 发送mail,很久之前整过,没做记录,这次整理下做个 ... -
java ant 压缩与解压缩
2011-09-15 16:05 2411以下本文来自: http://blog.csdn.net/l ... -
Java源码中的发现:快速判断一个int值是几位数
2011-07-22 15:57 3995判断一个int值是几位数,要是我自己实现,估计又会想到除法和模 ... -
Weblogic 部署SSL
2011-07-15 16:14 891weblogic 部署SSL 整理网路上的 一部分由 ... -
CXF客户端配置请求超时限制
2011-07-13 17:14 5086在用cxf 开发webservice应用时,客户端老报 ... -
Weblogic的基础优化!
2011-07-04 16:43 1243由于项目需要,最近研究了一下系统优化。 系统性能优化是系 ... -
判断偶数几种方法性能
2011-06-24 17:06 1315判断一个数是否偶数,在编程中经常用的,大部分人都用的是 ... -
java读取文件夹下的所有文件夹和文件
2011-05-18 10:07 1380import java.io.FileNotFoundExce ... -
ThreadLocal的使用场景
2011-04-11 17:24 1060在Java的多线程编程中,为保证多个线程对共享变量的安全访问, ... -
Java 进制之间互相转换
2011-03-30 13:34 1240public static void main(String[ ... -
B/S架构下applet,JNI实现对客户端硬件的读取
2011-03-26 10:20 1483昨天整个Applet 调用JNI 实现读取指纹的Demo,郁闷 ...
相关推荐
在Netbeans中使用Struts2.0+Spring2.5+Hibernate框
hibernate3.2.5 for netbeans6.1,6.1版本可以安装,其他的不清楚,找了好长时间,哈哈……奉献了……要是好的话,帮我顶顶
免费的如eclipse,netbeans等,收费的如myelipse,jbuilder,Intellij,Oracle workshop 等,各有特色。有了它们,我们的工作量减轻了不少,调试代码也变得轻松了。不过,对于咱们这些腰包本来就不丰裕的web开发者来说...
此留言板系统是在下学习中的一个练习程序,功能比较简单,初学者有兴趣可以参考一下(在下也是初学者~) ... 2、使用struts2+hibernate+spring 3、使用Dojo、Prototype、JSON 4、使用netbeans进行开发
使用JSF建立一个真实的Web应用程序不是没有意义的任务,这篇文章介绍了如何将JSF与Sping Framework和Hibernate集成,并且给出了使用这些技术建立这个真实的Web应用程序的最佳实践和设计指导.
Netbeans环境下使用GTK+. Netbeans环境下使用GTK+.
的SSH 架构,即Struts+Spring+Hibernate。其中Struts 框架负责“视图View— 控制器Control—模型Model”的导航。而JSF 的出现,给了程序员们一个取代 Structs 的机会。笔者也是初接触JSF,但很快被它的方便、简洁所...
可用于NetBeans6.1 6.0修改启动参数的插件
netbeans struts2.0 spring2的插件和jar 找的太辛苦了,找齐了,便宜点送给大家了
nbstruts2support,当前的netbeans即使是6.5版本也只是支持struts1,该插件可以使其支持struts2,下载该两个插件,打开“工具”-->“插件”选择已下载,将插件导入,打上勾,安装即可
netbeans7.0上可以使用的struts2架构插件
网上书店比较完整的实现,...使用netbeans6.5+mysql。代码的里边的默认包有一个sql文件是使用navicat导出的数据库数据。同时还有我自己编写的ActionCreator,DaoCreator等Creator系列。具体的项目细节可以去我的博客 ...
官方最新版,txt中有迅雷下载地址,复制地址到新建任务里就ok了!
《Java Web开发技术大全:JSP+Servlet+Struts+Hibernate+Spring+Ajax》内容包括Web客户端技术、JSP/Servlet技术、Struts 2(*、类型转换、输入校验、上传和下载文件、Struts 2的各种标签、对 AJAX的支持等)、Spring...
在netbeans中提供struts2的支持
netbeans7.2_struts2_plugin插件
NetBeans Struts2 插件 惟一一个支持Struts2的IDE
Struts2 Spring2 Hibernate3 整合实例; 数据库MySql 5; IDE: NetBeans6.9 也可导入到MyEclipse中。 保证能够实现。 请先看内部的说明文件。
《Java Web开发技术大全:JSP+Servlet+Struts+Hibernate+Spring+Ajax》内容包括Web客户端技术、JSP/Servlet技术、Struts 2(*、类型转换、输入校验、上传和下载文件、Struts 2的各种标签、对 AJAX的支持等)、Spring...