A
Amit Jain
I hava created a working Struts 1.2 webapp.
I want to add Spring support and I have tried to use
ContextLoaderPlugIn and DelegateProxy for this, but I recive an 404
error saying Servlet action is not available where action referes to
the org.apache.struts.action.ActionServlet class defined in web.xml.
I can't seem to fix this and would appreciate any help solving this
matter.
struts-config.xml
Code:
..
..
..
<action path="/springTest" type="no.rone.struts.SpringTestAction" />
..
..
..
<action path="/sindex"
type="org.springframework.web.struts.DelegatingActionProxy"
validate="false">
<forward name="success" path="/index.jsp"/>
</action>
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
..
..
..
DelegatingActionProxy.class
// Decompiled by DJ v3.2.2.67 Copyright 2002 Atanas Neshkov Date:
6/9/2007 10:52:45 AM
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check
often for new version!
// Decompiler options: packimports(3)
// Source File Name: DelegatingActionProxy.java
package org.springframework.web.struts;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
import org.apache.struts.config.ModuleConfig;
import org.springframework.beans.BeansException;
import org.springframework.web.context.WebApplicationContext;
// Referenced classes of package org.springframework.web.struts:
// DelegatingActionUtils
public class DelegatingActionProxy extends Action
{
public DelegatingActionProxy()
{
}
public ActionForward execute(ActionMapping mapping, ActionForm
form, HttpServletRequest request, HttpServletResponse response)
throws Exception
{
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,
org.apache.struts.action.Action.class);
}
protected WebApplicationContext
getWebApplicationContext(ActionServlet actionServlet, ModuleConfig
moduleConfig)
throws IllegalStateException
{
return
DelegatingActionUtils.findRequiredWebApplicationContext(actionServlet,
moduleConfig);
}
protected String determineActionBeanName(ActionMapping mapping)
{
return DelegatingActionUtils.determineActionBeanName(mapping);
}
}
SpringIndexAction .java
Code:
/*
* Generated by Eclipse Struts
*/
package ca.nexcel.books.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import ca.nexcel.books.business.ProductManager;
/**
* Eclipse Struts
* Creation date: 06-04-2007
*/
public class SpringIndexAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
private ProductManager productManager;
public final ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setAttribute("products", productManager.findAll());
System.out.println("");System.out.println("");
System.out.println("*** SpringIndexAction ***");
System.out.println("");System.out.println("");
return mapping.findForward("success");
}
public final void setProductManager(ProductManager productManager)
{
this.productManager = productManager;
}
}
applicationContext.xml
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://
www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="/sindex" class="ca.nexcel.books.actions.SpringIndexAction">
<property name="productManager"><ref bean="productManager"/></
property>
</bean>
<bean id="productManager"
class="ca.nexcel.books.business.ProductManager"></bean>
</beans>
Does anyone have a clue?
I want to add Spring support and I have tried to use
ContextLoaderPlugIn and DelegateProxy for this, but I recive an 404
error saying Servlet action is not available where action referes to
the org.apache.struts.action.ActionServlet class defined in web.xml.
I can't seem to fix this and would appreciate any help solving this
matter.
struts-config.xml
Code:
..
..
..
<action path="/springTest" type="no.rone.struts.SpringTestAction" />
..
..
..
<action path="/sindex"
type="org.springframework.web.struts.DelegatingActionProxy"
validate="false">
<forward name="success" path="/index.jsp"/>
</action>
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
..
..
..
DelegatingActionProxy.class
// Decompiled by DJ v3.2.2.67 Copyright 2002 Atanas Neshkov Date:
6/9/2007 10:52:45 AM
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check
often for new version!
// Decompiler options: packimports(3)
// Source File Name: DelegatingActionProxy.java
package org.springframework.web.struts;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;
import org.apache.struts.config.ModuleConfig;
import org.springframework.beans.BeansException;
import org.springframework.web.context.WebApplicationContext;
// Referenced classes of package org.springframework.web.struts:
// DelegatingActionUtils
public class DelegatingActionProxy extends Action
{
public DelegatingActionProxy()
{
}
public ActionForward execute(ActionMapping mapping, ActionForm
form, HttpServletRequest request, HttpServletResponse response)
throws Exception
{
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,
org.apache.struts.action.Action.class);
}
protected WebApplicationContext
getWebApplicationContext(ActionServlet actionServlet, ModuleConfig
moduleConfig)
throws IllegalStateException
{
return
DelegatingActionUtils.findRequiredWebApplicationContext(actionServlet,
moduleConfig);
}
protected String determineActionBeanName(ActionMapping mapping)
{
return DelegatingActionUtils.determineActionBeanName(mapping);
}
}
SpringIndexAction .java
Code:
/*
* Generated by Eclipse Struts
*/
package ca.nexcel.books.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import ca.nexcel.books.business.ProductManager;
/**
* Eclipse Struts
* Creation date: 06-04-2007
*/
public class SpringIndexAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
private ProductManager productManager;
public final ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setAttribute("products", productManager.findAll());
System.out.println("");System.out.println("");
System.out.println("*** SpringIndexAction ***");
System.out.println("");System.out.println("");
return mapping.findForward("success");
}
public final void setProductManager(ProductManager productManager)
{
this.productManager = productManager;
}
}
applicationContext.xml
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://
www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="/sindex" class="ca.nexcel.books.actions.SpringIndexAction">
<property name="productManager"><ref bean="productManager"/></
property>
</bean>
<bean id="productManager"
class="ca.nexcel.books.business.ProductManager"></bean>
</beans>
Does anyone have a clue?