??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲一欧洲中文字幕在线,亚洲精品久久久久无码AV片软件,亚洲第一永久AV网站久久精品男人的天堂AVhttp://www.tkk7.com/badboy/category/5951.htmlzh-cnTue, 27 Feb 2007 12:18:17 GMTTue, 27 Feb 2007 12:18:17 GMT60Struts Classic 的变q(下)Q从1.1?.2 http://www.tkk7.com/badboy/articles/46247.htmlbadboybadboyMon, 15 May 2006 09:05:00 GMThttp://www.tkk7.com/badboy/articles/46247.htmlhttp://www.tkk7.com/badboy/comments/46247.htmlhttp://www.tkk7.com/badboy/articles/46247.html#Feedback0http://www.tkk7.com/badboy/comments/commentRss/46247.htmlhttp://www.tkk7.com/badboy/services/trackbacks/46247.htmlStruts1.2.4

新特?/h2>

主要修改Q?/h3>

不赞成特?/strong>
Struts1.1中已l有很多构造不再赞成用。许多已l被删除了。所以在升?.2.4Ӟ请clean-compile 你的应用Qƈ且deprecation warnings 被打开。在升?.2.4之前强烈解决所有decprecated 的用法。最可能应用开发h员的用法是:

    1. org.apache.struts.Action statics: 如今使用org.apache.struts.Global statics
    2. Action.perform: 如今使用Action.execute

虽然没有被删除也没有被标明ؓ不赞成用,最好还是将ActionErrors 替换为ActionMessages 以确保正的操作?
TagUtils ?/strong>ModuleUtils
许多以前在org.apache.struts.utils.RequestUtils中找到的工具Ҏ如今UdCorg.apache.struts.taglibs.TagUtils 或org.apache.struts.utils.ModuleUtils包中?
GenericDataSource / GenericConnection 实现被删?/strong>
datasources manager 仍然支持Q但是我们自qdatasource implementationis q不被支持。很Ƣ迎你插入自qDataSource 实现Q但是我们没有资源来l护我们自己的实现。如果你的容器不支持DataSource实现Q推荐用Jakarta Commons?DBCP package?
Validator 增强

  1. ValidWhen

Struts Validator 如今支持ValidWhen 规则Q以便一个验证可以依赖于另一个验证?/p>

  1. IntRange 现在可以select-one 和radio 字段。比如:q得我们可以用一些有效的选项加上一个具有诸?Choose one" 标题q且gؓ"-1"的附加选项来组装一个组合框。那么当用户试图提交一个表单时Q你可以值是否ؓ-1Q从而决定是否没有选择选项?
  2. 你现在可以强制进行客LJavascript 验证来检所有约束,而不是停留在W一个错误之处。方法是讄Validator PlugIn上的一个新的属性stopOnFirstError为false?a >
  3. "required" 验证现在可以checkboxes, radio,select-one, ?select-multiple 字段cd。参见修改后的Validator CZ来看如何使用q些新的特征?
  4. 一个标准的validateUrl 规则可以让你能够某一个属性是否包含一个格式正的URL?

DigestingPlugIn
一个新的标准PlugIn 可以帮助你在application范围内创Z自己的对象图Qobject graphQ。这是创ZAction调用的业务对象的快捷方式。请参见最新的MailReader CZ来看如何使用DigestingPlugin?
ModuleConfigVerifier
虽然不是全新的,一个标准类Q用来验证模块配|,位于PlugIn 包。ModuleConfigVerifier 主要认Struts对象囄各中lg被蝲入。但是,开发h员可扩展此类来检查确保Struts 配置文g的内部一致性?
提供了支持Maven的项目文?/strong>.
新的配置DTD
推荐使用struts-config_1_2.dtd。新的DTD d了两个新的元?lt;display-name> ?<description> 到struts-config 元素中。这些元素可用于struts配置文g工具和文档生工兗在Struts 1.2.x 中,已有的Struts 配置文g可以使用两个版本的DTD 都可载入?
新的Taglib URIs
标签库的URI已经被修改已反映Struts从Jakarta Ud了Apache 的顶U项目。ؓ了兼容,使用旧的URI的TLD仍然有效Q但是鼓׃用新的URI?
Struts-Chain
试验性的Q这个新?contrib" package 使用了Jakarta Sandbox中的Responsibilty package 的Chainin 来创Z个新的RequestProcessor的Breed。未来版本可能会成ؓ默认实现?
MappingDispatchAction
一个新的标准ActionQ将控制转发到ActionMapping 参数命名的一个方法?
Cancel handlers
DispatchAction, LookupDispatchAction, ?MappingDispatchAction Q如今提供了默认的可以覆写的cancel handler。也可以指定默认的handler name?
Session-scoped ActionMessages
现在你可以将ActionMessages 保存在session 中and have them cleaned up after the first use。现在除了Action.saveMessages() 消息保存在session中还有了另外一U选择。在消息已经被访问过一ơ之后ActionMessages.isAccessed() q回true。RequestProcessor.processCachedMessages() 查询isAccessed() 已决定是否应该将消息从session中删除?
JA Mailreader
Struts Mailreader Example 应用现在包含Japanese 资源文g?
Tiles EL
Tiles tags 如今可以通过Struts EL taglib使用ELQ后者基于JSTL?
Wildcard Mappings
现在可以在actiponMapping中用通配W。详l信息参见Struts Mailreader Example application?
Action attributes
html img tag d了Action 属性,以匹配html link tag?
Module attribute
Forward元素以及多个核心标签中新增一?module" 属性。这个属性允怽通过名称Q或者前~Q指定另一个模块来创徏模块间的直接链接。新的module 属性优于contextRelative属性,q且可以常用?SwitchAction"中?

Struts 1.2.7

主要修改

依赖?/h3>

Struts 对下列组件的依赖性发生了改变Q?


依赖?

新的版本

Commons BeanUtils

Version 1.7.0

Commons Digester

Version 1.6

Commons Validator

Version 1.1.4

Commons Collections

removed

Commons Lang

removed

Core Struts

Saving Messages in the Session

在action也新增了一个方法[saveErrors(HttpSession, ActionMessages)]来将errors 保存在Session 中,q且在其W一ơ被讉K之后被自动从Session中删除。这是等同于1.2.4 中message上新增的功能?

Re-directing ActionForward

ActionRedirect 是ActionForward 的一个子c,其设计来用于重定向请求,支持在运行时d参数?

Download Action

DownloadAction 是一个提供了下蝲文g的具体细节的抽象Action?

Dispatch Helper

ActionDispatcher 是一个提?em>DispatchAction cd的行Z是不必承自DispatchAction?

Lazy Validator Form

DynaBean 风格的ActionFormQ它不需要其属性被定义Qƈ提供Lazy List ?em>Lazy Map 行ؓ?

jars 中的配置文g

配置文g(? Struts config, Validator config ?Tiles 配置文g)现在可以被保存在jars。Struts 会像以前一h查servlet contextQ但是如果没扑ֈQ?Struts 会尝试classloader L找?

Tag Library 改变

Highlighting Errors

Struts现在可以使用HTML Input Tags上的 errorKey, errorStyle, errorStyleClass ?errorStyleId 属性自动高亮错误字Dc?

Readonly / Disabled Forms

现在可以使用<html:form> tag?em>readonly ?em>disabled属性来止或者全部的字D只诅R?br />N.B. readonly 属性只影响<html:text>, <html:textarea> ?<html:password> as per the HTML 4 specification?

HTML Tag Refactoring

许多HTML标签都被重构了,以便更易使用?/p>

  1. d了prepareOtherAttributes() Ҏ- 刚好在关闭元素之前调用,提供一个地Ҏ渲染额外的属性?
  2. name 属性渲染如今在prepareName() Ҏ中,以便更易提供定制行ؓ?
  3. value 属性如今在prepareValue() Ҏ中以便更易提供定制行为?
  4. 当渲染一个属性时Q这些标{在用属性的getter 而不是直接用实际的属性,q意味着如果你想Q比如覆盖TextTag?styleClass Q那么一个选择是覆盖getStyleClass()Ҏ?
  5. 属性的渲染现在使用一个简单的 prepareAttribute() Ҏ来?em>name="attribute" 格式Q多数属性渲染一个一行语句?

Bundle Attribute

bundle 属性被dC下列标签QButtonTag, CancelTag, CheckboxTag, FileTag, FrameTag, HiddenTag, LinkTag, MultiboxTag, PasswordTag, RadioTag, ResetTag, SelectTag, SubmitTag, TextTag, TextareaTag?

ErrorTag

现在新增?strong>header, footer, prefix, suffix属性?/strong>

Validator

Resource Bundle Support

Validator 配置文g?e.g. validation.xml)?lt;msg> ?<arg> 元素?em>bundle 属性现在随?lt;msg> ?em>resource 属性一起得到支持?
struts-examples webapp 中添加了新的面来展C对Resource Bundle 的支持?/em>

Struts1.2.8

主要改变

Struts 1.2.8 的主要改变是修正?em>Cross Site Scripting (XSS) q?



badboy 2006-05-15 17:05 发表评论
]]>Struts Classic 的变q(上)Q从1.0?.1 http://www.tkk7.com/badboy/articles/46245.htmlbadboybadboyMon, 15 May 2006 09:04:00 GMThttp://www.tkk7.com/badboy/articles/46245.htmlhttp://www.tkk7.com/badboy/comments/46245.htmlhttp://www.tkk7.com/badboy/articles/46245.html#Feedback0http://www.tkk7.com/badboy/comments/commentRss/46245.htmlhttp://www.tkk7.com/badboy/services/trackbacks/46245.html 最q在~写Struts教程的时候,把Struts1.1?.2的个版本变化ȝ了一下,希望能够从整体上把握它的变迁脉络Q在开发和l护的时候也可以参考参考?/font>



Struts1.1的修?/h1>

新特?/h2>

引入新的配置DTD

Struts 1.0 的配|DTD 已经不赞成用,引入了新的struts-config_1_1.dtd。在Struts 1.1 中,已有的Struts 配置文g可以使用q两个版本的DTD载入?

新的Commons 包依赖?/h3>

在Struts中用了多个Apache Jarkarta commons的组Ӟ而Commonslgq不仅仅可以用来构徏Struts应用。在Struts1.1中,所使用的Commonslg已经重构来外部依赖于Jarkarta Commons目Q而不?.0中的内部版本?
下面的Commons包包括了对相应的Struts 1.0 中的cȝ替代Q?

  1. BeanUtils [org.apache.commons.beanutils]Q?
    1. org.apache.struts.utils.BeanUtils
    2. org.apache.struts.utils.ConvertUtils
    3. org.apache.struts.utils.PropertyUtils.
  2. Collections [org.apache.commons.collections]
    1. org.apache.struts.util.ArrayStack
    2. org.apache.struts.util.FastArrayList
    3. org.apache.struts.util.FastHashMap
    4. org.apache.struts.util.FastTreeMap.
  3. Digester [org.apache.commons.digester]
    1. org.apache.struts.digester.*.

下面q几个包现在仍然被Struts框架的各U组件用:

  1. FileUpload [org.apache.commons.fileupload]
  2. Logging [org.apache.commons.logging]
  3. Validator [org.apache.commons.validator]

XML解析?/h3>

另外Q?/strong>Struts 1.1 需要符合JAXP/1.1 (而不是JAXP/1.0) API的XML解析器,比如JAXP/1.1 参考实现和Xerces 1.3.1+?

源代?/h3>

如果需要从源代码开始构建StrutsQ请使用Ant 1.4 以上版本?

集成Struts Validator

一个新的Commons Validatorlg被集成到Struts 1.1中,包含在新的Validator包中?

Tiles

引入了一个新的JSP模板l装机制TilesQ通过标签库提供集成?

Nested

Nested taglib l定CStruts1.1中,增强了现有Struts标签的功能?

新的CZ应用

Struts1.1发布包中包括了针对Validator 和Tiles的新的示例?

新的可选组?/h3>

CVS源代码库中新增了一个目录contribQ包含了很有用的Q但是没有集成到标准代码Z的扩展?

  1. Scaffold ?一个对Commons Scaffold 工具包扩展,旨在提供可重用的构徏Web应用的类
  2. Struts-EL ?可选的Struts-EL taglib 使得在Struts 中用JSTL更加Ҏ?需要Servlet 2.3 +容器支持)

Action 包的增加

基本的控制器框架 [org.apache.struts.action]新增了一下特征:

  1. ActionServlet 现在提供了对模块化应用的支持Qƈ且新增了多个扩展炏V?
  2. 新增了一个ActionMessages c,支持ActionErrors功能的一个超集,可以用于通用的消息收集传递,不仅仅针对errors?

Upload ?/h3>

文g上传c[org.apache.struts.upload]新增了一下特征:

  1. CommonsMultipartRequestHandlerQ这个新cM用Jakarta Commons FileUpload 包实C文g上传。这也是Struts的默认文件上传实现?

Util ?/h3>

工具QutilityQ类 [org.apache.struts.util]新增了以下特征:

  1. LocalStrings: 修正了与可替换参数相关的消息Q以便它不会d一个外来的无关的字W?
  2. LabelValueBean: 一个新c,定义了一个名值对的集合,可以用在<html:options> ?lt;html:optionsCollection>标签Q或者其它地斏V?
  3. MessageResources: 转移包含在特定消息字W串中的单引受?
  4. computeParameters: 允许事务令牌是唯一的参数?
  5. RequestUtils: 在构Z个查询字W串Ӟ修改来编码一?amp;受?

Bean Taglib

struts-bean 标签库[org.apache.struts.taglib.bean]中新增了以下特征Q?

  1. <bean:write>Q加入了format, locale ?bundle 属性以支持Ҏ用户当前场所q行格式化的功能Q格式化来自属性或者来自字W串资源的字W串?
  2. <bean:cookie>, <bean:header>, ?lt;bean:parameter>Q纠正了在标{?multiple"属性时Q所产生的脚本变量类型?
  3. <bean:message>Q加入了name, property, 和scope 属性,以便消息资源key 可以动态地从一个bean 或者bean 属性获得?

HTML Taglib

struts-html [org.apache.struts.taglib.html]加入了如下新特征Q?

  1. <html:link>: d?action' 属?
  2. <html:options>: 如果'property' 属性制定的属性(propertyQ返回nullQ现在标{ְ抛出一个错误消息指名实际问题而不是造成NPE?
  3. <html:option> ?<html:options>Q添加了'style' ?styleClass' 属性?
  4. <html:optionsCollection>Q新标签。提供了一个更清晰的方式来从集合组装HTML options?
  5. <bean:message>Q添加了'name', 'property' ?scope' 属性,以便消息资源key 可以动态地从bean获得?
  6. <html:messages>Q新标签。可以通过新的ActionMessages cM的一个消息集合进行P代?
  7. ActionFormQ现在,此标{֜它初始化ActionForm Bean的时候会调用reset() Ҏ。它也要求被标签所实例化的bean 是ActionForm 的一个子cR?
  8. <html:image>Q添加了'align' attribute?
  9. <html:img>Q添加了mouse 事g属?'onclick', 'ondblclick', 'onmousedown', 'onmouseup', 'onmouseover', 'onmousemove', 'onmouseout')?
  10. SubmitTag, SelectTag, LinkTag.java, CheckboxTag, ButtonTag, ImageTag, RadioTag, 和TextArea 标签Q?d了indexed 属性?

Logic Taglib

struts-logic 标签库[org.apache.struts.taglib.logic]加入了如下新特征Q?

  1. <logic:empty> ?lt;logic:notEmpty>Q新标签。类g<logic:present> ?lt;logic:notPresent>Q但对空字符串的处理不同?

Template Taglib

无变化,但无赞成使用。推荐用Tiles.

q性层面的改变

加入了Config Package

  1. ControllerConfigQ添加了inputForward 属性以指示ActionMapping.input是一个forward 而不是URI?
  2. ControllerConfigQ添加了forwardPattern 和inputPattern 到help 应用面模块的理面目录
  3. d了一个新的包以提供更多的灉|性来支持控制器配|和多模块应用的支持?

Action ?br />

基本框架(org.apache.struts.action)q行了如下修Ҏ者修正:

  1. Action cM的所有常敎ͼ不赞成用。提取到新的GlobalscM?
  2. ActionMappingQ如果模块的ControllerConfig bean [org.apache.struts.config.ControllerConfig]的inputForward 讄为trueQinput 属性将引用一个ActionForward 而不是模块相对的路径?
  3. ActionServletQ添加了convertNull 参数以在l装Form时仿真Struts 1.0 行ؓ。如果设|ؓtrueQ数值numeric Java wrapper cȝ?(如java.lang.Integer) 默认ؓnull (而不?)?
  4. ActionServletQ添加了"config/$foo" 参数Q不赞成使用包中的其他参数?
  5. ActionForms 和相关类Qؓ了保存资源,现在在响应toStringh的时候用一个StringBuffer?
  6. LookupDispatchActionQ添加的新的标准ActionQ以帮助在国际化的按钮之间进行选择?
  7. ActionForm c:修改来用ActionServletWrapper 而不是暴露ActionServlet?
  8. ActionServletWrapper c:d的新c,用于ActionFormQ以防止ActionServlet 的公开字符串属性被通过查询字符串改写?
  9. Action.MAPPING_KEY?request 属性: 如果没有指定form beanQ无条g地将选择的mapping 传递ؓh属?"org.apache.struts.action.mapping.instance")?
  10. ActionServlet:避免了在初始化Servletp|的时候导致的NullPointerException?
  11. ActionForm c:现在是真正的serializableQ因Z个非serializable 的实例变?servlet 和multipartRequestHandler) 已经成ؓtransient。但是,如果你的需要序列化和解序列化这个实例,你要自己负责重设q两个属性?
  12. ActionMessages 和ActionErrorsQThe initial order a property/key is added in is now retained.
  13. processActionForward(): 不赞成,推荐使用processForwardConfig

Upload?/h3>文g上传 (package org.apache.struts.upload) [ Upload 应用的一部分]作了如下修改和修正:
  1. CommonsMultipartRequestHandlerQ基于Jakarta Commons FileUpload 包的文g上传的新实现。这个新实现如今是默认实现?
  2. BufferedMultipartInputStreamQ解决了丢失字节的问题?
  3. ArrayIndexOutOfBoundsExceptionQ解决了已知的错误?
  4. Multipart requestsQBetter reporting for premature closing of input streams while reading multipart requests.
  5. 新行字符QNew line charactersQ:解决了上传和新换行字W时D的文件损坏问题?

Utility?/h3>

utilities (package org.apache.struts.util)发生如下修改和修正:

  1. RequestUtilsQ添加了对ControllerConfig 的forwardPattern, pagePattern, 和inputForward 属性的支持?
  2. GenericDataSourceQ不赞成。修改ؓ作ؓ[org.apache.commons.dbpc.BasicDataSource]的一个薄的Wrapper。徏议直接用BasicDataSource 或其它兼容组件?
  3. RequestUtils c:修改Z用ActionServletWrapper而不是暴?ActionServlet?
  4. 为getActionErrors ?getActionMessages Ҏd了错误消息?
  5. getActionErrors ?getActionMessagesQ添加了ҎZ传入的消息关键字从Request范围获取的对象来产生正确的相应对象的Ҏ?
  6. ActionErrors ?ActionMessagesQ创Z个这U对象的逻辑被移CRequestUtils中的一个工h法?
  7. JspException 消息Q现在在RequestUtils中生成?
  8. ConvertUtils.convertCharacter()Q现在将空字符串ƈq回默认倹{?

Bean Taglib?/h3>struts-bean c标签?[org.apache.struts.taglib.bean]发生了如下修改和修正Q?
  1. <html:errors>Q当指定了属性标{时Q如果指定的属性没有发生错误,则不会输出错误。而前面的错误L会被输出。未来的增强版本包括额外的属性来关闭header ?footer?
  2. helper Ҏ?private"改ؓ "protected" ?

HTML Taglib ?/h3>

struts-html 标签?package org.apache.struts.taglib.html)发生了如下修改和修正Q?

  1. FormTagQ修正ؓQ当指定了action mapping的名U时Q要排除查询字符丌Ӏ?
  2. ImgTagQ如果只有一个参敎ͼ能正地URLEncode 查询字符串参数?
  3. MultiboxTag.doAfterBody():Q修正ؓq回SKIP_BODY 而不是SKIP_PAGE?
  4. ErrortagQ不赞成使用defaultLocaleҎ?

Documentation CZ应用

Struts Documentation 应用(对应Struts |站的内?发生了如下修改:

  1. 重新l织了资源到单独的页面中?
  2. 在Tag Developers Guide中,d了更详细的文件上传要求?
  3. 在Building View ComponentsQ澄清了额外的i18n 支持可以由浏览器提供Qƈ且超Z框架的范围?
  4. 在Building Controller Components一节,文 'validating' init-paramQ添加了各种参数的默认|澄清了某些web.xml 讄不是Struts特定的?
  5. Tag library 文Q移到User's Guide下?

MailReader CZ应用

Struts MailReader Example Application 发生如下修改和修正:

  1. d了应用资源的 Russian 和Japanese 译Qƈ且设|JSP的字W集?UTF-8"以便其可以显CEnglish 或Japanese?
  2. 在Struts配置文g中交换了Edit mappings?attribute" 属性的"name" ?
  3. 删除了对"tour"文档中的保存的数据库数据的引用,因ؓq个功能已经被删除?

Exercise Taglib CZ应用

Struts Exercise Taglib Example Application 发生了如下修改和修正Q?

  1. d了针对用了"action"属性的<html:link> 的test case ?
  2. d了针对基于保存在page上下文中的集合?lt;html:options> ?<html:optionsCollection>?lt;html:select> 的test case?

不同之处

q里列出1.0?.1中新增的cd已经不赞成用的c:

1.0中不赞成使用Q?.1中已l删除的cR?/h3>
  1. 删除Qorg.apache.struts.utils.BeanUtils, org.apache.struts.utils.ConvertUtils, and org.apache.struts.utils.PropertyUtils ?替换为org.apache.commons.beanutils
  2. 删除Qorg.apache.struts.util.ArrayStack, org.apache.struts.util.FastArrayList, org.apache.struts.util.FastHashMap, org.apache.struts.util.FastTreeMap ?替换为org.apache.commons.collections
  3. 删除Q?org.apache.struts.digester.* - 替换为org.apache.commons.digester
  4. 删除Qstruts-config.dtd ?替换为struts-config_1_1.dtd.
  5. 删除Qomnibus "struts" taglib 和其相应的TLD ?替换为bean, logic, 和html taglib?
  6. 删除Q?form" taglib 和其相应的TLD ?替换为html taglib.

Struts 1.1新增的包

  1. config
  2. taglib.nested
  3. taglib.nested.bean
  4. taglib.nested.html
  5. taglib.nested.logic
  6. validator

Struts 1.1新增的类

action

  1. ActionMessage
  2. ActionMessages
  3. DynaActionForm
  4. DynaActionFormClass
  5. ExceptionHandler
  6. RequestProcessor

actions

  1. LookupDispatchAction

taglib.html

  1. FrameTag
  2. JavascriptValidatorTag
  3. MessagesTag
  4. OptionsCollectionTag

taglib.logic

  1. EmptTag
  2. MessagesNotPresentTag
  3. MessagesPresentTag
  4. NotEmptyTag

upload

  1. CommonsMultipartRequestHandler

util

  1. LabelValueBean

Struts 1.1中新增的cL?/h3>

action.Action

  1. ACTION_SERVLET_KEY
  2. APPLICATION_KEY
  3. MESSAGE_KEY
  4. PLUG_INS_KEY
  5. REQUEST_PROCESSOR_KEY
  6. execute
  7. getResources(javax.servlet.http.HttpServletRequest)
  8. saveMessages

action.ActionServlet

  1. configDigester
  2. convertHack
  3. log
  4. processor
  5. getInternal
  6. destroyApplications
  7. destroyConfigDigester
  8. getApplicationConfig
  9. getRequestProcessor
  10. initApplicationConfig
  11. initApplicationDataSources
  12. initApplicationPlugIns
  13. initApplicationMessageResources
  14. initConfigDigester
  15. methods created for backward-compatiblity only
    1. defaultControllerConfig
    2. defaultFormBeansConfig
    3. defaultForwardsConfig
    4. defaultMappingsConfig
    5. defaultMessageResourcesConfig

taglib.html.BaseHandlerTag

  1. indexed
  2. setIndexed
  3. getIndexed

Struts 1.0 到Struts 1.1不赞成的c?/h3>

action

  1. ActionException
  2. ActionFormBeans
  3. ActionForwards
  4. ActionMappings

Struts 1.0 不赞成的cL?/h3>

action.Action

  1. FORM_BEANS_KEY
  2. FORWARDS_KEY
  3. MAPPINGS_KEY
  4. getResources()
  5. perform

ActionServlet

  1. findDataSource
  2. findFormBean
  3. findForward
  4. findMapping
  5. initDataSources
  6. methods created for backward-compatiblity only
    1. defaultControllerConfig
    2. defaultFormBeansConfig
    3. defaultForwardsConfig
    4. defaultMappingsConfig
    5. defaultMessageResourcesConfig


badboy 2006-05-15 17:04 发表评论
]]>扩展Strutshttp://www.tkk7.com/badboy/articles/45849.htmlbadboybadboyFri, 12 May 2006 07:21:00 GMThttp://www.tkk7.com/badboy/articles/45849.htmlhttp://www.tkk7.com/badboy/comments/45849.htmlhttp://www.tkk7.com/badboy/articles/45849.html#Feedback0http://www.tkk7.com/badboy/comments/commentRss/45849.htmlhttp://www.tkk7.com/badboy/services/trackbacks/45849.html作者:Sunil Patil

?/span>

我见q许多项目开发者实现自׃有的MVC框架。这些开发者ƈ不是因ؓ惛_C同于Struts的某些功能,而是q没有意识到怎么L展Struts。通过开发自qMVC框架Q你可以掌控全局Q但同时q也意味着你必M出很大的代hQ在目计划很紧的情况下也许Ҏ׃可能实现?br />
Struts不但功能强大也易于扩展。你可以通过三种方式来扩展Struts:

1.PlugInQ在应用启动或关闭时L行某业务逻辑Q创Z自己的PlugInc?br />
2.RequestProcessorQ在h处理阶段一个特定点Ʋ执行某业务逻辑Q创Z自己的RequestProcessor。例如:你想l承RequestProcessor来检查用L录及在执行每个请求时他是否有权限执行某个动作?br />
3.ActionServletQ在应用启动或关闭或在请求处理阶D|执行某业务逻辑Q承ActionServletcR但是必M只能在PligIn和RequestProcessor都不能满你的需求时候用?br />
本文会列举一个简单的Struts应用来示范如何用以上三U方式扩展Struts。在本文末尾资源区有每种方式的可下蝲样例源代码。Struts Validation 框架?Tiles 框架是最成功两个的Struts扩展例子?br />
我是假设读者已l熟悉Struts框架q知道怎样使用它创建简单的应用。如想了解更多有关Struts的资料请参见资源区?br />
PlugIn

ҎStruts文Q“PlugIn是一个须在应用启动和关闭旉被通知的模块定制资源或服务配置包”。这是_你可以创Z个类Q它实现PlugIn的接口以便在应用启动和关闭时做你惌的事?br />
假如创徏了一个web应用Q其中用Hibernate做ؓ持久化机Ӟ当应用一启动Q就需初始化HinernateQ这样在web应用接收到第一个请求时QHibernate已被配置完毕q待命。同时在应用关闭时要关闭Hibernate。跟着以下两步可以实现Hibernate PlugIn的需求?br />
1.创徏一个实现PlugIn接口的类Q如下:

public class HibernatePlugIn implements PlugIn{
        private String configFile;
        // This method will be called at application shutdown time
        public void destroy() {
                System.out.println("Entering HibernatePlugIn.destroy()");
                //Put hibernate cleanup code here
                System.out.println("Exiting HibernatePlugIn.destroy()");
        }
        //This method will be called at application startup time
        public void init(ActionServlet actionServlet, ModuleConfig config)
                throws ServletException {
                System.out.println("Entering HibernatePlugIn.init()");
                System.out.println("Value of init parameter " +
                                    getConfigFile());
                System.out.println("Exiting HibernatePlugIn.init()");
        }
        public String getConfigFile() {
                return name;
        }
        public void setConfigFile(String string) {
                configFile = string;
        }
}


实现PlugIn接口的类必须是实C下两个方法:
init() 和destroy().。在应用启动时init()被调用,关闭destroy()被调用。Struts允许你传入初始参数给你的PlugInc;Z传入参数你必dPlugInc里为每个参数创Z个类似JavaBean形式的setterҎ。在HibernatePlugInc里Q欲传入configFile的名字而不是在应用里将它硬~码q去

2.在struts-condig.xml里面加入以下几行告知Strutsq个新的PlugIn

<struts-config>
        ...
        <!-- Message Resources -->
        <message-resources parameter=
          "sample1.resources.ApplicationResources"/>

        <!-- Declare your plugins -->
        <plug-in className="com.sample.util.HibernatePlugIn">
                <set-property property="configFile"
                   value="/hibernate.cfg.xml"/>
        </plug-in>
</struts-config>

ClassName属性是实现PlugIn接口cȝ全名。ؓ每一个初始化传入PlugIncȝ初始化参数增加一?lt;set-property>元素。在q个例子里,传入config文的名Uͼ所以增加了一个config文路径?lt;set-property>元素?br />
Tiles和Validator框架都是利用PlugInl初始化d配置文g。另外两个你q可以在PlugInc里做的事情是:

假如应用依赖于某配置文gQ那么可以在PlugInc里查其可用性,假如配置文g不可用则抛出ServletException。这导致ActionServlet不可用?br />
PlugIn接口的init()Ҏ是你改变ModuleConfigҎ的最后机会,ModuleConfigҎ是描q基于Struts模型静态配|信息的集合。一旦PlugIn被处理完毕,Struts׃ModuleCOnfigȝh?br />
h是如何被处理?/span>

ActionServlet是Struts框架里唯一一个ServletQ它负责处理所有请求。它无论何时收到一个请求,都会首先试着为现有请求找C个子应用。一旦子应用被找刎ͼ它会为其生成一个RequestProcessor对象Qƈ调用传入HttpServletRequest和HttpServletResponse为参数的process()Ҏ?br />
大部分请处理都是在RequestProcessor.process()发生的。Process()Ҏ是以模板ҎQTemplate MethodQ的设计模式来实现的Q其中有完成request处理的每个步骤的ҎQ所有这些方法都从process()Ҏ序调用。例如,L当前h的ActionFormcd查当前用h否有权限执行action mapping都有几个单独的方法。这l我们提供了极大的弹性空间。Struts的RequestProcessorҎ个请求处理步骤都提供了默认的实现Ҏ。这意味着Q你可以重写你感兴趣的方法,而其余剩下的保留默认实现。例如,Struts默认调用request.isUserInRole()查用h否有权限执行当前的ActionMappingQ但如果你需要从数据库中查找Q那么你要做的就是重写processRoles()ҎQƈҎ用户角色q回true ?false?br />
首先我们看一下process()Ҏ的默认实现方式,然后我将解释RequestProcessorc里的每个默认的ҎQ以便你军_要修改请求处理的哪一部分?br />
public void process(HttpServletRequest request,
                        HttpServletResponse response)
    throws IOException, ServletException {
        // Wrap multipart requests with a special wrapper
        request = processMultipart(request);
        // Identify the path component we will
        // use to select a mapping
        String path = processPath(request, response);
        if (path == null) {
            return;
        }
        if (log.isDebugEnabled()) {
            log.debug("Processing a '" + request.getMethod() +
                      "' for path '" + path + "'");
        }
        // Select a Locale for the current user if requested
        processLocale(request, response);
        // Set the content type and no-caching headers
        // if requested
        processContent(request, response);
        processNoCache(request, response);
        // General purpose preprocessing hook
        if (!processPreprocess(request, response)) {
            return;
       }
        // Identify the mapping for this request
        ActionMapping mapping =
            processMapping(request, response, path);
        if (mapping == null) {
            return;
        }
        // Check for any role required to perform this action
        if (!processRoles(request, response, mapping)) {
            return;
        }
        // Process any ActionForm bean related to this request
        ActionForm form =
            processActionForm(request, response, mapping);
        processPopulate(request, response, form, mapping);
        if (!processValidate(request, response, form, mapping)) {
            return;
        }
        // Process a forward or include specified by this mapping
        if (!processForward(request, response, mapping)) {
            return;
        }
        if (!processInclude(request, response, mapping)) {
            return;
        }
        // Create or acquire the Action instance to
        // process this request
        Action action =
            processActionCreate(request, response, mapping);
        if (action == null) {
            return;
        }
        // Call the Action instance itself
        ActionForward forward =
            processActionPerform(request, response,
                                action, form, mapping);
        // Process the returned ActionForward instance
        processForwardConfig(request, response, forward);
    }



1、processMultipart(): 在这个方法中QStrutsdrequest以找出contentType是否为multipart/form-data。假如是Q则解析q将其打包成一个实现HttpServletRequest的包。当你成生一个放|数据的HTML FORMӞrequest的contentType默认是application/x-www-form-urlencoded。但是如果你的form的inputcd是FILE-type允许用户上蝲文gQ那么你必须把form的contentType改ؓmultipart/form-data。如q样做,你永q不能通过HttpServletRequest的getParameter()来读取用h交的form|你必MInputStream的Ş式读取requestQ然后解析它得到倹{?br />
2、processPath(): 在这个方法中QStruts读取request的URI以判断用来得到ActionMapping元素的\径?br />
3、processLocale(): 在这个方法中QStruts得到当前request的LocaleQLocale假如被配|,作为org.apache.struts.action.LOCALE属性的D存入HttpSession。这个方法的附作用是HttpSession会被创徏。假如你不想此事发生Q可在struts-config.xml 文g里ControllerConfig的local属性设|ؓfalse,如下Q?br />
<controller>
        <set-property property="locale" value="false"/>
</controller>


4、processContent()Q?/b>通过调用response.setContentType()讄response的contentType。这个方法首先会试着的得到配|在struts-config.xml里的contentType。默认ؓtext/htmlQ重写方法如下:
<controller>
        <set-property property="contentType" value="text/plain"/>
</controller>


5、processNoCache()Q?/b>Strutsؓ每个response的设|以下三个headerQ假如已在struts 的config.xml配|ؓno-cache?br />
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 1);


假如你想讄为no-cache headerQ在struts-config.xml中加如以下几?br />
<controller>
        <set-property property="noCache" value="true"/>
</controller>


6、processPreprocess()Q?/b>q是一个一般意义的预处理hookQ其可被子类重写。在RequestProcessor里的实现什么都没有做,Lq回true。如此方法返回false会中断请求处理?br />
7、processMapping():q个Ҏ会利用path信息扑ֈActionMapping对象。ActionMapping对象在struts-config.xml file文g里表CZؓ<action>
<action path="/newcontact" type="com.sample.NewContactAction"
        name="newContactForm" scope="request">
        <forward name="sucess" path="/sucessPage.do"/>
        <forward name="failure" path="/failurePage.do"/>
</action>


ActionMapping元素包含了如Actioncȝ名称及在h中用到的ActionForm的信息,另外q有配置在当前ActionMapping的里的ActionForwards信息?br />
8、processRoles(): Struts的web 应用安全提供了一个认证机制。这是_一旦用L录到容器QStruts的processRoles()Ҏ通过调用request.isUserInRole()可以查他是否有权限执行给定的ActionMapping?br />        <action path="/addUser" roles="administrator"/>

假如你有一个AddUserActionQ限制只有administrator权限的用h能新d用户。你所要做的就是在AddUserAction 的action元素里添加一个gؓadministrator的role属性?br />
9、processActionForm()Q?/b>每个ActionMapping都有一个与它关联的ActionFormcRstruts在处理ActionMappingӞ他会?lt;action>里name属性找到相关的ActionFormcȝ倹{?br />
<form-bean name="newContactForm" 
           type="org.apache.struts.action.DynaActionForm">
                <form-property name="firstName"
                          type="java.lang.String"/>
                <form-property name="lastName"
                          type="java.lang.String"/>
</form-bean>


在这个例子里Q首先会查org.apache.struts.action.DynaActionFormcȝ对象是否在request 范围内。如是,则用它Q否则创Z个新的对象ƈ在request范围内设|它?br />
10、processPopulate():Q?/b>在这个方法里QStruts匹配的request parameters值填入ActionFormcȝ实例变量中?br />
11、processValidate()Q?/b>Struts调用ActionForm的validate()Ҏ。假如validate()q回ActionErrorsQStruts用戯{到由<action>里的input属性标C的面?br />
12、processForward() and processInclude()Q?/b>在这两个Ҏ里,Struts?lt;action>元素的forward和include属性的|假如有配|,则把forward和include h攑֜配置的页面内?br />
<action forward="/Login.jsp" path="/loginInput"/>
        <action include="/Login.jsp" path="/loginInput"/>


你可以从他们的名字看出其不同之处。processForward()调用RequestDispatcher.forward(),QprocessInclude()调用RequestDispatcher.include()。假如你同时配置了orward 和include 属性,StrutsM调用forwardQ因为forward,是首先被处理的?br />
13、processActionCreate()Q?/b>q个Ҏ?lt;action>的type属性得到ActioncdQƈ创徏q回它的实例。在q里例子中struts创Z个com.sample.NewContactActioncȝ实例?br />
14、processActionPerform()Q?/b>q个Ҏ调用Action cȝexecute()ҎQ其中有你写入的业务逻辑?br />
15、processForwardConfig()Q?/b>Actioncȝexecute()会q回一个ActionForwardcd的对象,指出哪一面展C给用户。因此Strutsؓq个面创徏RequestDispatchetQ然后再调用RequestDispatcher.forward()Ҏ?br />
以上列出的方法解释了RequestProcessor在请求处理的每步默认实现及各个步骤执行的序。正如你所见,RequestProcessor很有Ҏ,它允怽通过讄<controller>里的属性来配置它。例如,假如你的应用生成XML内容而不是HTMLQ你可以通过讄controller的某个属性来通知Struts?br />
创徏你自qRequestProcessor

从以上内Ҏ们已l明白了RequestProcessor的默认实现是怎样工作的,现在我将通过创徏你自qRequestProcessor.展示一个怎样自定义RequestProcessor的例子。ؓ了演C创Z个自定义RequestProcessorQ我修改例子实C下连个业务需求:

我们要创Z个ContactImageActionc,它将生成images而不是一般的HTMl面

在处理这个请求之前,通过查session里的userName属性来认用户是否d。假如此属性没有被扑ֈQ则用戯{到登录页面?br />

分两步来实现以上q个业务需求?br />创徏你自qCustomRequestProcessorc,它将l承RequestProcessorc,如下Q?br />
public class CustomRequestProcessor
    extends RequestProcessor {
        protected boolean processPreprocess (
            HttpServletRequest request,
            HttpServletResponse response) {
            HttpSession session = request.getSession(false);
        //If user is trying to access login page
        // then don't check
        if( request.getServletPath().equals("/loginInput.do")
            || request.getServletPath().equals("/login.do") )
            return true;
        //Check if userName attribute is there is session.
        //If so, it means user has allready logged in
        if( session != null &&
        session.getAttribute("userName") != null)
            return true;
        else{
            try{
                //If no redirect user to login Page
                request.getRequestDispatcher
                    ("/Login.jsp").forward(request,response);
            }catch(Exception ex){
            }
        }
        return false;
    }

    protected void processContent(HttpServletRequest request,
                HttpServletResponse response) {
            //Check if user is requesting ContactImageAction
            // if yes then set image/gif as content type
            if( request.getServletPath().equals("/contactimage.do")){
                response.setContentType("image/gif");
                return;
            }
        super.processContent(request, response);
    }
}


在CustomRequestProcessor cȝprocessPreprocessҎ里,查session的userName属性,假如没有扑ֈQ将用户转到d面?br />
对于产生images作ؓContactImageActioncȝ输出Q必要重写processContentҎ。首先检查其request是否h/contactimage路径Q如是则讄contentType为image/gifQ否则ؓtext/html?br />
加入以下几行代码到sruts-config.xml文g里的<action-mapping>后面Q告知Struts QCustomRequestProcessor应该被用作RequestProcessorc?br />
<controller>
        <set-property  property="processorClass"
        value="com.sample.util.CustomRequestProcessor"/>
</controller>


h意,假如你只是很生成contentType不是text/html输出的Actionc,重写processContent()没有问题。如不是q种情况Q你必须创徏一个Struts子系l来处理生成image  Action的请求ƈ讄contentType为image/gif

Title框架使用自己的RequestProcessor来装饰Struts生成的输出?br />
ActionServlet

假如你仔l研IStruts web应用的web.xml文gQ它看上dq样Q?br />
<web-app >
        <servlet>
            <servlet-name>action=</servlet-name>
            <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
            <!-- All your init-params go here-->
        </servlet>
        <servlet-mapping>
            <servlet-name>action</servlet-name>
            <url-pattern>*.do</url-pattern>
        </servlet-mapping>
</web-app >


q就是说QActionServlet负责处理所有发向Struts的请求。你可以创徏ActionServlet的一个子c,假如你想在应用启动和关闭时或每次h时做某些事情。但是你必须在承ActionServletcd创徏PlugIn ?RequestProcessor。在Servlet 1.1前,Title框架是基于承ActionServletcL装饰一个生成的response。但?.1开始,׃用TilesRequestProcessorcR?br />
l论

开发你自己的MVC模型是一个很大的军_——你必须考虑开发和l护代码的时间和资源。Struts是一个功能强大且E_的框Ӟ你可以修改它以其满你大部分的业务需求?br />
另一斚wQ也不要L地决定扩展Struts。假如你在RequestProcessor里放入一些低效率的代码,q些代码在每次h时执行ƈ大大地降低整个应用的效率。当然L创徏你自qMVC框架比扩展Struts更好的情c?br />

badboy 2006-05-12 15:21 发表评论
]]>
Hibernate2.1升到Hibernate3.0http://www.tkk7.com/badboy/articles/44306.htmlbadboybadboyMon, 01 May 2006 13:13:00 GMThttp://www.tkk7.com/badboy/articles/44306.htmlhttp://www.tkk7.com/badboy/comments/44306.htmlhttp://www.tkk7.com/badboy/articles/44306.html#Feedback0http://www.tkk7.com/badboy/comments/commentRss/44306.htmlhttp://www.tkk7.com/badboy/services/trackbacks/44306.html阅读全文

badboy 2006-05-01 21:13 发表评论
]]>
hibernate要点http://www.tkk7.com/badboy/articles/35598.htmlbadboybadboyThu, 16 Mar 2006 03:48:00 GMThttp://www.tkk7.com/badboy/articles/35598.htmlhttp://www.tkk7.com/badboy/comments/35598.htmlhttp://www.tkk7.com/badboy/articles/35598.html#Feedback0http://www.tkk7.com/badboy/comments/commentRss/35598.htmlhttp://www.tkk7.com/badboy/services/trackbacks/35598.htmlhttp://www.donews.net/dyhcn/
1.两种配置文gQ?
  A.hibernate.cfg.xml   ?nbsp;  B.hibernate.properties

  A中可含映文件的配置Q而B中hard codes加映文件?/P>

  A。Configuration config=new Configuration().config();
  B. Configuration config=new Configuration();
     config.addClass(TUser.class);


2.你不必一定用hibernate.cfg.xml或hibernate.propertiesq两文g名,
   你也不一定非得把配置文g攑֜Classes下,
   File file=new File("c:\\sample\\myhibernate.xml");
   Configuration config=new Configuration().config(file);

3. session.Flush()
   强制数据库立卛_步,当用事务Ӟ不必用flush,事务提交自动调用flush
   在session关闭时也会调用flush


4. HibernateL使用对象cd作ؓ字段cd

5. XDoclet专门建立了hibernate doclet,是在java代码上加上一?
   java docTagQ后来再让XDoclet分析该java代码Q生成映文?

6.HQL子句本n大小写无养I但是其中出现的类名和属性名必须注意大小写区分?/P>

7.关系Q?
  Constrained : U束Q表明主控表的主键上是否存在一个外键(foreigh keyQ?
   对其q行U束?

  property-ref:兌cM用于与主控类相关联的属性名Q默认ؓ兌cȝ主键属性名

  单向一对多需在一斚w|,双向一对多需在双方进行配|?/P>

8.lazy=false:被动方的记录由hibernate负责记取Q之后存攑֜LҎ定的
  Collectioncd属性中

9. java.util.Set或net.sof.hibernate.collecton.Bagcd的Collection


10.重要Qinverse:用于标识双向兌中的被动方一端?
         inverse=false的一方(L方)负责l护兌关系.默认|false

11.batch-size:采用延迟加蝲特征Ӟ一ơ读入的数据数昨?/P>

12.一对多通过LҎ斎ͼL方ؓ一ҎQ?/P>

   user.getAddresses().add(addr);
   session.save(user);//通过L对象U联更新  

13.在one-to-many 关系中,many 一方设Z动方Qinverse=falseQ将有助性能
   的改善。在一方设|关pLQinverse=true,卛_L权交l多方,
   q样多方可主动从一方获得foreign key,然后一ơinsert卛_完工?


   addr.setUser(user);//讄兌的TUser对象
   user.getAddresses().add(addr);
   session.save(user);//U联更新 

14.只有设ؓL方的一Ҏ兛_Q访问)Ҏ的属性,被动Ҏ不关心对方的属性的?/P>

15.one-to-many与many-to-one节点的配|属性不同:
   一对多关系多了lazy和inverse两个属?
   多对多节点属性:column:中间映射表中Q关联目标表的关联字D?
                   class:cdQ关联目标类
                   outer-join:是否使用外联?nbsp;   

   注意:access是设|属性值的d方式?/P>


        column是设|关联字Dc?


16.多对多,注意两方都要讄inverse和lazy,cascade只能设ؓinsert-update
   多对多关pMQ由于关联关pL两张表相互引用,因此在保存关pȝ态时必须对双方同时保存?

   group1.getRoles().add(role1);
   role1.getGroups().add(group1);

   session.save(role1);
   session.save(group1);

17.关于vo和po
   vol过hibernate定w处理Q就变成了po(该vo的引用将被容器保存,q且在session关闭时flush,因此po如果再传到其它地Ҏ变了Q就危险?
 
   vo和po怺转换QBeanUtils.copyProperties(anotherUser,user);

18.对于save操作而言Q如果对象已l与Session相关联(卛_l被加入Session的实体容器中Q,则无需q行具体的操作。因Z后的Session.flushq程中,Hibernate
会对此实体容器中的对象进行遍历,查找出发生变化的实体Q生成ƈ执行相应的update
语句?

19.如果我们采用了gq加载机Ӟ但希望在一些情况下Q实现非延迟?
载时的功能,也就是说Q我们希望在Session关闭后,依然允许操作user的addresses
属?
Hibernate.initializeҎ可以通过强制加蝲兌对象实现q一功能Q?
q也正是我们Z么在~写POJOӞ必须用JDK Collection接口Q如Set,MapQ?
而非特定的JDK Collection实现c(如HashSet、HashMapQ申明Collection属性的
原因?

20.事务Q从sessionFactory获得session,其自动提交属性就已经关闭(AutoCommit=false),此时若执行了jdbc操作Q如果不昑ּ调用session.BeginTransaction(),是不会执行事务操作的?/P>

   jdbc transaction:Z同一个session(是同一个connection)的事?
   jta  transaction:跨sessionQ跨connectionQ事?

   对于jta事务Q有三种实现ҎQ?
     A。UserTransaction tx=new InitialContext().lookup("...");
        tx.commit();
     B. 使用hibernate装的方法:(不推?
        Transaction tx=session.beginTransaction();
        tx.commit();
     C. 使用ejb之sessionBean的事务技持方法,你只要在把需要在发布描述W中Q把需要jta事务的方法声明ؓrequire卛_

21.悲观锁,乐观锁:
   乐观锁一般通过version来实玎ͼ注意version节点必须出现在id后?


22.Hibernate中,可以通过Criteria.setFirstResult和Criteria.setFetchSizeҎ讑֮分页范围?
   Query接口中也提供了与其一致的ҎQhibernate主要在dialectcM实现在这个功能?


23.cache
   <hibernate-configuration>
 <session-factory>
 …?
  <property name="hibernate.cache.provider_class">
   net.sf.ehcache.hibernate.Provider
  </property> 

  q需对ecache本nq配|?
  <ehcache>
 <diskStore path="java.io.tmpdir"/>
 <defaultCache
 maxElementsInMemory="10000" //Cache中最大允怿存的数据数量
 eternal="false" //Cache中数据是否ؓ帔R
 timeToIdleSeconds="120" //~存数据钝化旉
 timeToLiveSeconds="120" //~存数据的生存时?
 overflowToDisk="true" //内存不Ӟ是否启用盘~存
 />
  </ehcache>

  之后在映文件中指定各个映射实体的cache{略
  <class name=" org.hibernate.sample.TUser" .... >
 <cache usage="read-write"/>
 ....
 <set name="addresses" .... >
  <cache usage="read-only"/>
 ....
 </set>
 </class>

 *****************************************************
 Query.list()跟Query.iterate()的不同:
 对于query.list()L通过一条sql语句获取所有记?然后其dQ填入pojoq回;
 但是query.iterate()Q则是首先通过一条Select SQL 获取所有符合查询条件的记录?
idQ再对这个id 集合q行循环操作Q通过单独的Select SQL 取出每个id 所对应的记
录,之后填入POJO中返回?

 也就是说Q对于list 操作Q需要一条SQL 完成。而对于iterate 操作Q需要n+1
条SQL。,listҎ不会从Cache中读取数据。iterator却会?


24.ThreadLocal:它会为每个线E维护一个私有的变量I间。实际上Q?
其实现原理是在JVM 中维护一个MapQ这个Map的key 是当前的线E对象,而value则是
U程通过ThreadLocal.setҎ保存的对象实例。当U程调用ThreadLocal.getҎӞ
ThreadLocal会根据当前线E对象的引用Q取出Map中对应的对象q回?

 q样QThreadLocal通过以各个线E对象的引用作ؓ区分Q从而将不同U程的变量隔d
来?


25.Hibernate官方开发手册标准示?
  public class HibernateUtil {
private static SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory
sessionFactory = new
Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
throw new RuntimeException(
"Configuration problem: " + ex.getMessage(),
ex
);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException
{
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}


    
26.通过filter实现session的重用:
   public class PersistenceFilter implements Filter
{
protected static ThreadLocal hibernateHolder = new ThreadLocal();
public void doFilter(ServletRequest request, ServletResponse
response, FilterChain chain)
throws IOException, ServletException
{
hibernateHolder.set(getSession());
try
{
…?
chain.doFilter(request, response);
…?
}
finally
{
Session sess = (Session)hibernateHolder.get();
if (sess != null)
{
hibernateHolder.set(null);
try
{
sess.close();
}
catch (HibernateException ex) {
throw new ServletException(ex);
}
}
}
}
……}

27.Spring的参数化事务理功能相当强大Q笔者徏议在ZSpring Framework的应?
开发中Q尽量用容器管理事务,以获得数据逻辑代码的最佛_L?
 
public class UserDAO extends HibernateDaoSupport implements IUserDAO
{
public void insertUser(User user) {
getHibernateTemplate().saveOrUpdate(user);
}
}


  上面的UserDAO实现了自定义的IUserDAO接口Qƈ扩展了抽象类Q?
HibernateDaoSupport
HibernateSupport实现了HibernateTemplate和SessionFactory实例的关联?
HibernateTemplate对Hibernate Session操作q行了封装,?
HibernateTemplate.executeҎ则是一装机制的核?

  *在spring的配|文仉Q移植了整个hibernate.cfg.xml的内宏V?/P>

badboy 2006-03-16 11:48 发表评论
]]>
վ֩ģ壺 һۺƵ| Ƶվѹۿ| ٸ̫ˬ߹ۿƵ | ˴ֳսŮ2021ƷƵ | С˵ͼƬ| ߿Ƭ˳Ӿ| ޺ÿƬӰ| պҹTVӰԺ| 91͵ֻ߹ۿ| 57PAO˹Ƶ| ŷձƷ| ëƬѹۿƵ| ɫŮһ| ȫɫƴɫƬѾþ| 337Pձŷ޴ͼ| AV߹ۿ| պƵ| ۺɫӰ| 91Ʒֻ| AV߹ۿ| ձػػƴ̼Ƭ| ޾Ʒһۺ| ҹþþӰԺ| Ļ߹ۿձ| һƬ߲| AVɫ| þþžѸƵ| ޾Ʒ˳߹ۿ| ѵվ߹ۿ| 㽶Ƶ߹ۿ| þþƷۺר| ëƬƵ߹ۿ| žžžƷƵ| ձ㽶Ƶ| ѿһػaaƬ| 91ƵƷȫѹۿ| ҹһӰԺ| ?vŮ˵߹ۿ| Ѳһ| AVר߳| ޾Ʒav|