| <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> |
| public ActionForward execute(){ Action delegateAction = getDelegateAction(mapping); return delegateAction.execute(mapping, form, request, response); } |
| protected Action getDelegateAction(ActionMapping mapping) throws BeansException { WebApplicationContext wac = getWebApplicationContext(getServlet(), mapping.getModuleConfig()); String beanName = determineActionBeanName(mapping); return (Action) wac.getBean(beanName, Action.class); } |
| wac=(WebApplicationContext)actionServlet.getServletContext().getAttribute( ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX); |
| <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> |
| WebApplicationContext = createWebApplicationContext(servletContext, parent); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context); |
| Return DelegatingActionUtils.findRequiredWebApplicationContext(actionServlet, moduleConfig); 换成下边方法 | |
| ServletContext sc = actionServlet.getServletContext(); WebApplicationContext wac = null; wac = WebApplicationContextUtils.getWebApplicationContext(sc); return wac; | |
| 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> | |