??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品视频福利,精品国产乱码久久久久久虫虫漫画,综合色中文字幕http://www.aygfsteel.com/sonnylys/category/31017.html熟能生yQy夺天工!zh-cnThu, 08 May 2008 17:39:31 GMTThu, 08 May 2008 17:39:31 GMT60Spring与Struts集成开?/title><link>http://www.aygfsteel.com/sonnylys/archive/2008/03/01/183112.html</link><dc:creator>无羽苍鹰</dc:creator><author>无羽苍鹰</author><pubDate>Sat, 01 Mar 2008 03:08:00 GMT</pubDate><guid>http://www.aygfsteel.com/sonnylys/archive/2008/03/01/183112.html</guid><wfw:comment>http://www.aygfsteel.com/sonnylys/comments/183112.html</wfw:comment><comments>http://www.aygfsteel.com/sonnylys/archive/2008/03/01/183112.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sonnylys/comments/commentRss/183112.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sonnylys/services/trackbacks/183112.html</trackback:ping><description><![CDATA[<p><br /> Spring与Struts集成开?br /> <br /> 最q喜Ƣ将所学的东西理顺一下,且发现写blog可以达成q目的?br /> 那就来整理一下我对Spring与Struts集成开发的一些想法?br /> <br /> 首先认pȝ的结构ؓ三层的B/S模式l构Q如下图Q?br /> <img style="width: 514px; height: 339px" height="339" alt="" src="http://www.aygfsteel.com/images/blogjava_net/sonnylys/three.jpg" width="514" border="0" /><br /> 在图中看出,Spring和Struts集成开发中QSpring在业务逻辑层被使用Q集成)。因为Spring框架的依赖注入,AOP及可声明的事务管理方面的技术优势,使得用Spring来管理业务实体,实体之间的依赖关p,业务逻辑服务接口变得单且可配|。至此我们要清楚Q?span style="color: red">Spring和Struts集成开发中QSpring在业务逻辑层被使用Q集成)?/span><br /> <br /> 清楚Struts和Spring在系l结构中分别充当的角色后Q接下来要讨论:<span style="color: #000000"><span style="color: #ff0000">如何实现集成</span>Q?br /> <strong style="color: #0000ff">1、用Spring的ActionSurpertc集成Struts?/strong><br /> org.springframework.web.struts.ActionSurpert是一个承org.apache.struts.action.Action的类Q简要代码如下:<br /> public abstract class ActionSurpert extends Action {<br />      private WebApplicationContext webApplicationContext;<br />      public void setServlet(ActionServlet actionServlet) {//<span style="color: red">当容器实例化此Action时被容器调用<br /> </span>           surper.setServlet(actionServlet);<br />            if(actionServlet != null) {<br />               this.webApplicationContext = initWebApplicationContext(actionServlet);//<span style="color: red">获取webApplicationContext<br /> </span>               //........<br />            }else{<br />              //.......<br />            }           <br />      } <br />      <br />      //通过getXXX()Ҏ(gu)获取   webApplicationContext 对象<br />      protected final WebApplictionContext getWebApplicationContext() {<br />             return this.webApplicationContext;<br />     }<br /> }<br /> 通过上述代码可以看出Q所有承了ActionSupportcȝAction可以通过WebApplicationContext对象的getBean(beanKey)Ҏ(gu)获得Spring配置文g中定义的各种Bean?br /> WebApplicationContext要由Web Server来加载,有两U方法:<br /> Q、通过org.springframework.web.struts.ContextLoaderPlugIn加蝲QContextLoaderPlugIn是个插gQ需要在Struts配置文g中配|?br /> <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"><br />    <set-property property = "contextConfigLocation" value="/WEB-INF/applicationContext.xml"></set-property><br /> </plug-in><br /> 2、在web.xml文g中加?br /> <context-param><br />   <param-name>contextConfigLocation</param-name><br />  <param-value>/WEB-INF/applicationContext.xml</param-value><br /> </context-param><br /> <servlet><br />  <servlet-name>context</servlet-name><br /> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-name><br /> <load-on-startup>1</load-on-startup><br /> </servlet><br /> 举个单的例子说明一下相关配|信息:<br /> 假定有ExampleActionQExampleBeanQExampleServiceq几个类Q它们工作流E是Q?br /> 用户hExampleActionQExampleAction调用ExampleService的接口方法对ExampleBeanq行相关的操作?br /> 1、applicationContext.xml中配|相关的bean信息<br /> <beans><br /> <bean id="<span style="color: red">dataSource</span>" class="org.springframework.jdbc.datasource.DriverManagerDataSource"><br />   <property name="driverClassName"><br />    <value>com.mysql.jdbc.Driver</value><br />   </property><br />   <property name="url"><br />    <value>jdbc:mysql://localhost:3306/ssh?useUnicode=true&amp;characterEncoding=UTF-8</value><br />   </property><br />   <property name="username"><br />    <value>root</value><br />   </property><br />   <property name="password"><br />    <value>root</value><br />   </property><br />  </bean><br /> <bean id="<span style="color: red">exampleBean</span>" class="org.mypackge.beans.ExampleBean"/><br /> <bean id="<span style="color: red">exampleBeanService</span>" class="org.mypackge.services.ExampleService"/>@<br /> </beans><br /> 通过q样配置后,在ExampleAction中可以用getWebApplicationContext() 获得webApplicationContext对象Q然后通过<br /> webApplicationContext的getBean(<span style="color: red">beanKey</span>)Ҏ(gu)获得相应的beanq行业务处理。标了红色的"beanKey"是applicationContext.xml?lt;bean>元素定义的bean idQ如:webApplicationContext.getBean("<span style="color: red">exampleBeanService</span>")。@<br /> <br /> 当然QExampleActionq要在stuts-config.xml配置文g中配|,q里不作介绍?br /> <strong style="color: #0000ff">2、用Spring的Action代理集成Struts</strong><br /> q种集成方式的核心思想是,Struts的配|文件中的所有Action的type属性设为org.springframwork.web.struts.DelegationActionProxy。当用户hActionӞ执行这代理Q代理会在Spring应用上下文中扑ֈ真正的ActionQ然后交l它处理用户的请求。而真正用于处理用戯求的Action的配|放在了Spring的配|文件中。这PStruts中的Action以及其依赖关pd可以用Spring容器来管理,比如业务逻辑对象注入到Action中,供其使用。简单片D?lt;bean<span style="color: #ff99cc"> name="/exampleAction" </span>class="org.myproj.struts.actions.ExampleAction"><br /> ....<br /> </bean><br /> 说明Q用name属性而不是用id来标识这个Bean,Spring不允许ID中出?/"Q而name可以Q?name"属性D和struts-config.xml文g中相?lt;action>元素中的path属性值相?span style="color: #ff99cc">(<action path="/exampleAction"</span>)Q这样Action代理才能扑ֈ相应的Action来处理请求?br /> <br /> Ƣ迎讨论Q提出宝贉|见?br /> <br /> <br /> </p> </span> <img src ="http://www.aygfsteel.com/sonnylys/aggbug/183112.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sonnylys/" target="_blank">无羽苍鹰</a> 2008-03-01 11:08 <a href="http://www.aygfsteel.com/sonnylys/archive/2008/03/01/183112.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>struts与hibernate集成开?/title><link>http://www.aygfsteel.com/sonnylys/archive/2008/02/29/183017.html</link><dc:creator>无羽苍鹰</dc:creator><author>无羽苍鹰</author><pubDate>Fri, 29 Feb 2008 10:44:00 GMT</pubDate><guid>http://www.aygfsteel.com/sonnylys/archive/2008/02/29/183017.html</guid><wfw:comment>http://www.aygfsteel.com/sonnylys/comments/183017.html</wfw:comment><comments>http://www.aygfsteel.com/sonnylys/archive/2008/02/29/183017.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sonnylys/comments/commentRss/183017.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sonnylys/services/trackbacks/183017.html</trackback:ping><description><![CDATA[struts与hibernate集成开?br /> 最q学习struts与hibernate相关知识Q下面是个h对struts与hibernate集成开发的一些见解,写出来跟大家共同讨论、学习,Ƣ迎指教?br />  要集成struts与hibernateq行开发,首先应该了解一下struts和hibernate框架各自的工作原理和模式般的开发流E?br /> 首先介绍struts的大概工作流E,下面通过一张struts工作的时序图来说明其工作程Q?br /> <img height="527" alt="" src="http://www.aygfsteel.com/images/blogjava_net/sonnylys/active.jpg" width="555" border="0" /><br /> Struts工作程分析Q?br /> 1QWeb服务器启动,初始化ActionServlet,dstruts-config.xml文g配置信息Q把q些信息分发到相应的对象中?br /> 2Q用户发求后QActionServlet接收到请求,查找与请求匹配的Action映射对象QActionMapping)对象是否存在Q是Q将h以及Actionform对象传递给相应的Action对象?br /> <span style="color: red"><strong>3QAction调用业务逻辑服务接口Q结合ActionFormQ对用户的请求做出处理?/strong><br /> </span>4QAction处理完毕q回ActionForward对象lActionServlet。ActionForward对象包含了{发目标对象,可以是jsp或Action?br /> 5)ActionServletҎ(gu)ActionForward对象的指向l{发请求,重复从第2步进行处理?br /> xQ我们对struts 的基本工作流E有个整体的认识Q但q没提hibernate相关的Q何知识,业务逻辑层也只是在第3)点微提一下?br /> <br /> 接下来,我们来看下hibernate是怎样工作的?(注:在这不是讨论QRQ的实现Q只讨论怎让hibernateqORM中间件工作)<br /> Hibernate是个独立的框Ӟ它不依赖M的Web Server或Application ServerQ就是说不需要这些支持?br /> Hibernate有五个核心接口,分别为Configuratoin, SessionFactory, Session,Query及Criteria。通过q些接口可以完成hibernate的初始化Q对持久化对象进行存取,更新{操作?br /> 下面要介始一下这些接口?br /> 1、Configuration接口 是Hibernate应用的入口,在开始用Hibernate的各U功能之前需要先创徏Configuration对象。它负责加蝲Hibernate 应用配置文gQ如Configuration cf = new Configuration.configure("com/myproj/hibernate/configs/hibernate.cfg.xml");<br /> 2、SessionFactory接口 ~存了Configuration对象所包含的配|信息,能根据映信息自动生成SQL语句Qƈ提供生成Session对象的方法?br /> 3、Session接口提供一pd持久化的操作?br /> 到此Q可以写一段代码来加看下如何使用hibernate<br /> Configuration cf = new Configuration.configure("com/myproj/hibernate/configs/hibernate.cfg.xml");//配置文g不在此作介绍<br /> SessionFactory sessionFactory = cf.buildSessionFactory();<br /> Session session = sessionFactory.openSession();<br /> session.update();<br /> session.save();{等持久化操作?br /> xQ简单介l了hibernate 是怎样工作的,其实我只惌你清楚:“<span style="color: red">Hibernate是个独立的框Ӟ它不依赖M的Web Server或Application ServerQ就是说不需要这些支持?#8221;<br /> </span><br /> 那么Q我们要回到主题来:如何集成struts与hibernate开发?{案很简单:hibernate和struts本质上是没什么联pȝQ只要你CQ?span style="color: red">Hibernate是个独立的框Ӟ它不依赖M的Web Server或Application Server?/span>用DAO模式把hibernate持久化的操作装好,供业务逻辑服务c调用就可以。回q头来看struts工作时序图的解释的W三点:“<span style="color: red"><strong>3QAction调用业务逻辑服务接口Q结合ActionFormQ对用户的请求做出处理?/strong></span>”Q不隑־出:<br /> 用户h后,struts负责扑ֈ相应的Action对象QAction调用业务逻辑服务接口Q业务逻辑服务接口调用DAO接口(q里默认的实现就用hibernate,当然, q可以有多种Ҏ(gu)据库操作的实玎ͼ<br /> hibernate充当下面q张图中?持久层(DAOQ?<br /> <img height="468" alt="" src="http://www.aygfsteel.com/images/blogjava_net/sonnylys/bs.jpg" width="535" border="0" /><br /> <br /> ׃本h对struts及hibernate认识不深Q写q篇文章只是抛砖引玉Q希望高手们发表意见指正错误Q多指教?br /> <br /> <br /> <br /> <br /> <br /> <img src ="http://www.aygfsteel.com/sonnylys/aggbug/183017.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sonnylys/" target="_blank">无羽苍鹰</a> 2008-02-29 18:44 <a href="http://www.aygfsteel.com/sonnylys/archive/2008/02/29/183017.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʯʨ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ȩ</a>| <a href="http://" target="_blank">մ</a>| <a href="http://" target="_blank">Ӫ</a>| <a href="http://" target="_blank">㺺</a>| <a href="http://" target="_blank">Ρɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɳ</a>| <a href="http://" target="_blank">Ӫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ԣ</a>| <a href="http://" target="_blank">մ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">㰲</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">˱</a>| <a href="http://" target="_blank">β</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ĵ</a>| <a href="http://" target="_blank">ˮ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">گ</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank">Զ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ӻ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">¸</a>| <a href="http://" target="_blank">¡</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>