国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Spring,Struts整合方法
關(guān)于Spring , Struts結(jié)合學(xué)習(xí)。
一、前言
剛剛接觸了日本一個(gè)項(xiàng)目,用的框架名稱是Northland Framework,主要用到以下部分
Struts、Spring、iBATIS、Velocity。Struts、Spring如何結(jié)合在一起?
二、Spring提供了三種整合Struts的方法:
使用 Spring 的 ActionSupport 類整合 Structs
使用 Spring 的 DelegatingRequestProcessor 覆蓋 Struts 的 RequestProcessor
將 Struts Action 管理委托給 Spring 框架
(參見Get a better handle on Struts actions, with Spring
http://www-128.ibm.com/developerworks/java/library/j-sr2.html?ca=drs-tp4105
對(duì)應(yīng)還有譯文:
http://gocom.primeton.com/modules/techresource/article504.htm?utm_campaign=searchengine&utm_source=baidu&utm_medium=jjpm&utm_term=Spring+Struts)
三、我只關(guān)心第三種整合方法:
這種方法通過Spring提供的兩個(gè)和Struts相關(guān)類來實(shí)現(xiàn):org.springframework.web.struts. DelegatingActionProxy,org.springframework.web.struts. ContextLoaderPlugIn。
ContextLoaderPlugIn實(shí)現(xiàn)Struts的PlugIn接口,只要在struts-config.xml中有如下配置:
<action    path="/searchSubmit">
type="ca.nexcel.books.actions.DelegatingActionProxy"
input="/searchEntry.do"
validate="true"
name="searchForm">
<forward name="success" path="/WEB-INF/pages/detail.jsp"/>
<forward name="failure" path="/WEB-INF/pages/search.jsp"/>
</action>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/beans.xml"/>
</plug-in>
ActionServlet裝載的時(shí)候就可以順便裝載和Spring相關(guān)的beans.xml,和beans.xml中相關(guān)的一個(gè)東西叫做WebApplicationContext , (在Spring里關(guān)鍵就是取得WebApplicationContext,取得這個(gè)也就可以用Spring管理業(yè)務(wù)),在ContextLoaderPlugIn中是這樣保存WebApplicationContext:
String attrName = getServletContextAttributeName();
getServletContext().setAttribute(attrName, wac);
再看DelegatingActionProxy,它繼承于Struts的Action,以后struts-config.xml中所有的
Action-mapping都要指向它,只是每個(gè)Action-mapping的path不同,將來也是用這個(gè)path來區(qū)分究竟需要執(zhí)行beans.xml中的那個(gè)類。如下代碼:
public ActionForward execute(){
Action delegateAction = getDelegateAction(mapping);
return delegateAction.execute(mapping, form, request, response);
}
這里的delegateAction就是beans.xml中一個(gè)相關(guān)的類(beans.xml也要求類繼承于Struts的Action) 去看看怎么得到delegateAction:
protected Action getDelegateAction(ActionMapping mapping) throws BeansException {
WebApplicationContext wac = getWebApplicationContext(getServlet(),
mapping.getModuleConfig());
String beanName = determineActionBeanName(mapping);
return (Action) wac.getBean(beanName, Action.class);
}
是如何取得WebApplicationContext呢:
wac=(WebApplicationContext)actionServlet.getServletContext().getAttribute(        ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX);
SERVLET_CONTEXT_PREFIX 正是 前邊提到的ContextLoaderPlugIn中 的attrName。
現(xiàn)在這個(gè)原理一目了然,ContextLoaderPlugIn在actionServlet初始化過程中保存
起來留到后面供DelegatingActionProxy用。
四、在另一篇文章中提到在上面的方法中OpenSessionInView Filter不能用
(參照http://wyyhzc.itpub.net/),這個(gè)東西我也不熟悉,是不是有不少Spring的東西在這種方式中都不能用呢? 這就說到另一種取得Spring WebApplicationContext的方法:
在web.xml中配置ContextLoaderListener:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/beans.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
對(duì)應(yīng)的beans.xml和前邊那個(gè)一樣,Log4jConfigListener先不用管,去查看相關(guān)文檔。
Web服務(wù)啟動(dòng)的時(shí)候,我們?nèi)タ纯碈ontextLoaderListener作了什么:
WebApplicationContext = createWebApplicationContext(servletContext, parent);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);
同樣是保存WebApplicationContext,但是key是ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
怎么才能不用ContextLoaderPlugIn而只用ContextLoaderListener?下面我修改
org.springframework.web.struts. DelegatingActionProxy 把它修改成
ca.nexcel.books.actions. DelegatingActionProxy并且修改一下代碼:
修改getWebApplicationContext方法
Return DelegatingActionUtils.findRequiredWebApplicationContext(actionServlet,
moduleConfig); 換成下邊方法
ServletContext sc = actionServlet.getServletContext();
WebApplicationContext wac = null;
wac = WebApplicationContextUtils.getWebApplicationContext(sc);
return wac;
并且在struts-config.xml中將action的type指向自己的
ca.nexcel.books.actions. DelegatingActionProxy,PlugIn刪除web.xml加上剛才提到的Listener,啟動(dòng)tomcat運(yùn)行一切正常。
五、我把northland的配置文件貼出來。
Struts-config.xml:
<action-mappings>
<action
path="/list"
input="/list.jsp"
name="_list"
scope="request"
type="jp.co.nec.hnes.northland.web.struts.FlowAction"
>
<display-name>一覧畫面</display-name>
</action>
<action
path="/register"
input="/register.jsp"
name="_register"
scope="request"
type="jp.co.nec.hnes.northland.web.struts.FlowAction"
>
<display-name>登録畫面</display-name>
</action>
Web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:flowConfig.xml,
classpath:viewConfig.xml,
classpath:applicationContext.xml,
classpath:applicationContext-extra.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>ActionServlet</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>
</servlet>
從中可以看到
其中的jp.co.nec.hnes.northland.web.struts.FlowAction和
ca.nexcel.books.actions. DelegatingActionProxy的功能差不多。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
spring在web.xml中和在struts中的不同配置 - gwt600的專欄 - C...
spring階段性的一點(diǎn)感受
Java普通類獲取Spring XML中Bean的方法總結(jié)
spring MVC3深入研究(2)
spring源碼研究之IoC容器在web容器中初始化過程 - ljbal - JavaEy...
轉(zhuǎn):SpringMVC理解之一:應(yīng)用上下文webApplicationContext
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服