Announcement Announcement Module
Collapse
No announcement yet.
Problem while spring-struts Integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem while spring-struts Integration

    I am using the existing jpetstore application for the spring-struts Integration with some changes
    My spring version is spring-framework-1.2.2


    I have done following steps for Integration



    Struts-config.xml:-

    Code:
     
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE struts-config PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
              "http&#58;//jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    
    <struts-config>
    
        <form-beans>
            <form-bean name="accountForm" type="org.springframework.samples.jpetstore.web.struts.AccountActionForm"/>
            <form-bean name="cartForm" type="org.springframework.samples.jpetstore.web.struts.CartActionForm"/>
            <form-bean name="emptyForm" type="org.springframework.samples.jpetstore.web.struts.BaseActionForm"/>
            <form-bean name="workingAccountForm" type="org.springframework.samples.jpetstore.web.struts.AccountActionForm"/>
            <form-bean name="workingOrderForm" type="org.springframework.samples.jpetstore.web.struts.OrderActionForm"/>
            <form-bean name="LoginForm" type="org.springframework.samples.jpetstore.web.struts.LoginForm"/>
    
        </form-beans>
    
        <global-forwards>
            <forward name="failure" path="/WEB-INF/jsp/struts/Error.jsp" redirect="false"/>
            <forward name="unknown-error" path="/WEB-INF/jsp/struts/Error.jsp"/>
            <forward name="global-signon" path="/WEB-INF/jsp/struts/SignonForm.jsp"/>
        </global-forwards>
    
        <action-mappings>        
     <!--                             
        <action path="/loginAction" type="org.springframework.web.struts.DelegatingActionProxy"
                name="LoginForm" scope="request" validate="false" parameter="method">
                <forward name="success" path="/WEB-INF/jsp/spring/SignonForm.jsp"/>
                <forward name="failure" path="/login.jsp"/>
        </action>
    -->
    
    <!--
            <action path="/loginAction" type="org.springframework.samples.jpetstore.web.struts.LoginAction" 
                    name="LoginForm" validate="false" scope="request" input="/login.jsp ">
                <forward name="success" path="/WEB-INF/jsp/struts/SignonForm.jsp" />
                <forward name="failure" path="/login.jsp"/>
            </action>
    -->
        
            <action path="/shop/addItemToCart" type="org.springframework.samples.jpetstore.web.struts.AddItemToCartAction"
                    name="cartForm" scope="session" validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/Cart.jsp"/>
            </action>
            <action path="/shop/checkout" type="org.springframework.samples.jpetstore.web.struts.ViewCartAction"
                    name="cartForm" scope="session" validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/Checkout.jsp"/>
            </action>
            <action path="/shop/editAccount" type="org.springframework.samples.jpetstore.web.struts.EditAccountAction"
                    name="workingAccountForm" scope="session" validate="true" input="/WEB-INF/jsp/struts/EditAccountForm.jsp">
                <forward name="success" path="/shop/index.do"/>
            </action>
            <action path="/shop/editAccountForm" type="org.springframework.samples.jpetstore.web.struts.EditAccountFormAction"
                    name="workingAccountForm" scope="session"   validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/EditAccountForm.jsp"/>
            </action>
            
            
            
          
            
            <action path="/shop/index" type="org.springframework.samples.jpetstore.web.struts.DoNothingAction"
                    validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/index.jsp"/>
            </action>
            
            
            
            
            
            <action path="/shop/listOrders" type="org.springframework.samples.jpetstore.web.struts.ListOrdersAction"
                    name="accountForm" scope="session" validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/ListOrders.jsp"/>
            </action>
            <!--
            <action path="/shop/newAccount" type="org.springframework.samples.jpetstore.web.struts.NewAccountAction"
                    name="workingAccountForm" scope="session" validate="true" input="/WEB-INF/jsp/struts/NewAccountForm.jsp">
                <forward name="success" path="/shop/index.do"/>
            </action>
            -->
            <action path="/shop/newAccountForm" type="org.springframework.samples.jpetstore.web.struts.NewAccountFormAction"
                    name="workingAccountForm" scope="session" validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/NewAccountForm.jsp"/>
            </action>
            <action path="/shop/newOrder" type="org.springframework.samples.jpetstore.web.struts.NewOrderAction"
                    name="workingOrderForm" scope="session" validate="true" input="/WEB-INF/jsp/struts/NewOrderForm.jsp">
                <forward name="confirm" path="/WEB-INF/jsp/struts/ConfirmOrder.jsp"/>
                <forward name="shipping" path="/WEB-INF/jsp/struts/ShippingForm.jsp"/>
                <forward name="success" path="/WEB-INF/jsp/struts/ViewOrder.jsp"/>
            </action>
            <action path="/shop/newOrderForm" type="org.springframework.samples.jpetstore.web.struts.NewOrderFormAction"
                    name="workingOrderForm" scope="session" validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/NewOrderForm.jsp"/>
            </action>
            <!--
            <action path="/shop/removeItemFromCart" type="org.springframework.samples.jpetstore.web.struts.RemoveItemFromCartAction"
                    name="cartForm" scope="session" validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/Cart.jsp"/>
            </action>
            -->
            
            <action path="/shop/searchProducts" type="org.springframework.samples.jpetstore.web.struts.SearchProductsAction"
                    name="emptyForm" scope="session" validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/SearchProducts.jsp"/>
            </action>
            
            <action path="/shop/signon" type="org.springframework.samples.jpetstore.web.struts.SignonAction"
                    name="accountForm" scope="session" validate="false">
                <forward name="success" path="/shop/index.do"/>
            </action>
            
            <!--
            <action path="/shop/signonForm" type="org.springframework.samples.jpetstore.web.struts.DoNothingAction"
                    validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/SignonForm.jsp"/>
            </action>
            -->
            
            <action path="/shop/updateCartQuantities" type="org.springframework.samples.jpetstore.web.struts.UpdateCartQuantitiesAction"
                    name="cartForm" scope="session" validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/Cart.jsp"/>
            </action>
            <action path="/shop/viewCart"/>      
            
            <!--
            <action path="/shop/viewCart" type="org.springframework.samples.jpetstore.web.struts.ViewCartAction"
                    name="cartForm" scope="session" validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/Cart.jsp"/>
            </action>
            -->
            
            
            
            
            
            
            
            
            
            
         &#91;b&#93;   <action path="/shop/viewCategory" />&#91;/b&#93;
            
            
            
            <!--
            <action path="/shop/viewCategory" type="org.springframework.samples.jpetstore.web.struts.ViewCategoryAction"
                    name="emptyForm" scope="session" validate="true" input="/WEB-INF/jsp/struts/index.jsp">
                <forward name="success" path="/WEB-INF/jsp/struts/Category.jsp"/>
            </action>
            -->
            
            
            
            
            
            
            
            
            
            <!--
            <action path="/shop/viewItem" type="org.springframework.samples.jpetstore.web.struts.ViewItemAction"
                    name="emptyForm" scope="session" validate="true" input="/WEB-INF/jsp/struts/Product.jsp">
                <forward name="success" path="/WEB-INF/jsp/struts/Item.jsp"/>
            </action>
            -->
            <!--
            <action path="/shop/viewOrder" type="org.springframework.samples.jpetstore.web.struts.ViewOrderAction"
                    name="accountForm" scope="session" validate="false">
                <forward name="success" path="/WEB-INF/jsp/struts/ViewOrder.jsp"/>
            </action>
            -->
            <action path="/shop/viewProduct" type="org.springframework.samples.jpetstore.web.struts.ViewProductAction"
                    name="emptyForm" scope="session" validate="true" input="/WEB-INF/jsp/struts/index.jsp">
                <forward name="success" path="/WEB-INF/jsp/struts/Product.jsp"/>
            </action>
            
        </action-mappings>
        
        &#91;b&#93;<controller>
                <set-property property="processorClass"
                              value="org.springframework.web.struts.DelegatingRequestProcessor"/>
        </controller>
           
        <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
            <set-property property="contextConfigLocation"
                          value="/WEB-INF/action-servlet.xml, /WEB-INF/dataAccessContext-local.xml, /WEB-INF/applicationContext.xml" />
        </plug-in>&#91;/b&#93;  
    
    </struts-config>

    In struts.config I have added the </controller> & <plug-in>

    My web.xml is as follows
    web.xml:-

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http&#58;//java.sun.com/dtd/web-app_2_3.dtd">
    
    <web-app>
    
        <display-name>Spring JPetStore</display-name>
    
        <description>Spring JPetStore sample application</description>
        
        
        <context-param>
            <param-name>webAppRootKey</param-name>
            <param-value>petstore.root</param-value>
        </context-param>
    
       
        <context-param>
            <param-name>log4jConfigLocation</param-name>
            <param-value>/WEB-INF/log4j.properties</param-value>
        </context-param>
    
    
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/dataAccessContext-local.xml  /WEB-INF/applicationContext.xml   
            </param-value>
            <!--
            <param-value>
                /WEB-INF/dataAccessContext-jta.xml  /WEB-INF/applicationContext.xml
            </param-value>
            -->
        </context-param>
    
        
     
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
    
        <servlet>
            <servlet-name>action</servlet-name>
            <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
            <load-on-startup>2</load-on-startup>
        </servlet>
    
        <!--
          - Spring web MVC servlet that dispatches requests to registered handlers.
          - Has its own application context, by default defined in "&#123;servlet-name&#125;-servlet.xml",
          - i.e. "petstore-servlet.xml" in this case.
          -
          - A web app can contain any number of such servlets.
          - Note that this web app has a shared root application context, serving as parent
          - of all DispatcherServlet contexts.
          
        
        <servlet>
            <servlet-name>petstore</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>3</load-on-startup>
        </servlet>
    
    -->
    
    
        <servlet>
            <servlet-name>remoting</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>4</load-on-startup>
        </servlet>
    
     
        <servlet>
            <servlet-name>axis</servlet-name>
            <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
            <load-on-startup>5</load-on-startup>
        </servlet>
    
    
        <servlet-mapping>
            &#91;b&#93;<servlet-name>action</servlet-name>&#91;/b&#93;
            <!--
            <servlet-name>petstore</servlet-name>
            
            -->
            <url-pattern>*.do</url-pattern>
        </servlet-mapping>
    
     
        <servlet-mapping>
            <servlet-name>remoting</servlet-name>
            <url-pattern>/remoting/*</url-pattern>
        </servlet-mapping>
    
       
        <servlet-mapping>
            <servlet-name>axis</servlet-name>
            <url-pattern>/axis/*</url-pattern>
        </servlet-mapping>
    
        <welcome-file-list>
            <welcome-file>index.html</welcome-file>
        </welcome-file-list>
    
       
    </web-app>
    Please note that here my <servlet-name> is action

    Now I have prepared action-servlet.xml
    My action-servlet.xml is as follows:-

    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <!--
      - DispatcherServlet application context for the Spring web MVC
        - implementation of JPetStore's web tier.
        -->
    <beans>
    
        <!-- ========================= VIEW DEFINITIONS ========================= -->
    
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
            <property name="prefix" value="/WEB-INF/jsp/spring/"/>
            <property name="suffix" value=".jsp"/>
        </bean>
    
    
        <!-- ========================= DEFINITIONS OF PUBLIC CONTROLLERS ========================= -->
    
        <bean id="defaultHandlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
    <!--
        <bean name="/shop/addItemToCart.do" class="org.springframework.samples.jpetstore.web.spring.AddItemToCartController">
            <property name="petStore" ref="petStore"/>
        </bean>
    -->
    <!--
        <bean name="/shop/checkout.do" class="org.springframework.samples.jpetstore.web.spring.ViewCartController">
            <property name="successView" value="Checkout"/>
        </bean>
    -->
    <!--
        <bean name="/shop/index.do" 
        </bean>
    -->
        <bean name="/shop/newAccount.do" class="org.springframework.samples.jpetstore.web.spring.AccountFormController">
            <property name="petStore" ref="petStore"/>
            <property name="validator" ref="accountValidator"/>
            <property name="successView" value="index"/>
        </bean>
    
        <bean name="/shop/removeItemFromCart.do" class="org.springframework.samples.jpetstore.web.spring.RemoveItemFromCartController"/>
    
        <bean name="/shop/signoff.do" class="org.springframework.samples.jpetstore.web.spring.SignoffController"/>
    <!--
        <bean name="/shop/searchProducts.do" class="org.springframework.samples.jpetstore.web.spring.SearchProductsController">
            <property name="petStore" ref="petStore"/>
        </bean>
    -->
    <!--
        <bean name="/shop/signon.do" class="org.springframework.samples.jpetstore.web.spring.SignonController">
            <property name="petStore" ref="petStore"/>
        </bean>
    -->
        <bean name="/shop/signonForm.do" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
            <property name="viewName" value="SignonForm"/>
        </bean>
    <!--
        <bean name="/shop/updateCartQuantities.do" class="org.springframework.samples.jpetstore.web.spring.UpdateCartQuantitiesController"/>
    -->
        <bean name="/shop/viewCart.do" class="org.springframework.samples.jpetstore.web.spring.ViewCartController">
            <property name="successView" value="Cart"/>
        </bean>
    
      
      
      
      
      
      
    &#91;b&#93;    <bean name="/shop/viewCategory" class="org.springframework.samples.jpetstore.web.spring.ViewCategoryController" >
            <property name="petStore" ref="petStore"/>
        </bean>&#91;/b&#93;
      
       
      
        <bean name="/shop/viewItem.do" class="org.springframework.samples.jpetstore.web.spring.ViewItemController">
            <property name="petStore" ref="petStore"/>
        </bean>
    <!--
        <bean name="/shop/viewProduct.do" class="org.springframework.samples.jpetstore.web.spring.ViewProductController">
            <property name="petStore" ref="petStore"/>
        </bean>
    -->
    
        <!-- ========================= DEFINITIONS OF PROTECTED CONTROLLERS ========================= -->
    
        <bean id="secureHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="interceptors">
                <list>
                    <ref bean="signonInterceptor"/>
                </list>
            </property>
            <property name="urlMap">
                <map>
                    <entry key="/shop/editAccount.do"><ref local="secure_editAccount"/></entry>
                    <entry key="/shop/listOrders.do"><ref local="secure_listOrders"/></entry>
                    <entry key="/shop/newOrder.do"><ref local="secure_newOrder"/></entry>
                    <entry key="/shop/viewOrder.do"><ref local="secure_viewOrder"/></entry>
                </map>
            </property>
        </bean>
    
        <bean id="signonInterceptor" class="org.springframework.samples.jpetstore.web.spring.SignonInterceptor"/>
    
        <bean id="secure_editAccount" class="org.springframework.samples.jpetstore.web.spring.AccountFormController">
            <property name="petStore" ref="petStore"/>
            <property name="validator" ref="accountValidator"/>
            <property name="successView" value="index"/>
        </bean>
    
        <bean id="secure_listOrders" class="org.springframework.samples.jpetstore.web.spring.ListOrdersController">
            <property name="petStore" ref="petStore"/>
        </bean>
    
        <bean id="secure_newOrder" class="org.springframework.samples.jpetstore.web.spring.OrderFormController">
            <property name="petStore" ref="petStore"/>
            <property name="validator" ref="orderValidator"/>
        </bean>
    
        <bean id="secure_viewOrder" class="org.springframework.samples.jpetstore.web.spring.ViewOrderController">
            <property name="petStore" ref="petStore"/>
        </bean>
    
    </beans>
    All other files are not changed.

    My Requirement:-

    I am initially displaying inde.html
    Then on clicking the link Enter the Store I am able to display the page index.jsp through struts action class

    Now when I click on the any of the viewCategoryId (Fish,cat,etc)I should be able to display the next page through the spring Controller

    note that I am doing changes to the /shop/viewCategory in struts-config.xml & action-servlet.xml

    Now I am getting the following error


    Code:
    org.springframework.beans.factory.BeanNotOfRequiredTypeException&#58; Bean named '/shop/viewCategory' must be of type &#91;org.apache.struts.action.Action&#93;, but was actually of type &#91;org.springframework.samples.jpetstore.web.spring.ViewCategoryController&#93;
    	org.springframework.beans.factory.support.AbstractBeanFactory.checkMergedBeanDefinition&#40;AbstractBeanFactory.java&#58;749&#41;
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;213&#41;
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;151&#41;
    	org.springframework.context.support.AbstractApplicationContext.getBean&#40;AbstractApplicationContext.java&#58;540&#41;
    	org.springframework.web.struts.DelegatingRequestProcessor.getDelegateAction&#40;DelegatingRequestProcessor.java&#58;161&#41;
    	org.springframework.web.struts.DelegatingRequestProcessor.processActionCreate&#40;DelegatingRequestProcessor.java&#58;142&#41;
    	org.apache.struts.action.RequestProcessor.process&#40;RequestProcessor.java&#58;220&#41;
    	org.apache.struts.action.ActionServlet.process&#40;ActionServlet.java&#58;1164&#41;
    	org.apache.struts.action.ActionServlet.doGet&#40;ActionServlet.java&#58;397&#41;
    	javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;689&#41;
    	javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;802&#41;
    My index.jsp in struts folder is as follows:-



    Code:
    <%@ include file="IncludeTop.jsp" %>
    
    <table border="0" cellspacing="0" width="100%">
      <tbody>
      <tr>
        <td valign="top" width="100%">
    
          <table align="left" border="0" cellspacing="0" width="80%">
            <tbody>
            <tr>
              <td valign="top">
    
                <!-- SIDEBAR -->
    
                <table bgcolor="#FFFF88" border="0" cellspacing="0" cellpadding="5" width="200">
                  <tbody>
          <tr>
          <td>
            <c&#58;if test="$&#123;!empty accountForm.account&#125;">
                        <b><i><font size="2" color="BLACK">Welcome <c&#58;out value="$&#123;accountForm.account.firstName&#125;"/>!</font></i></b>
            </c&#58;if>
            
          </td>
          </tr>
                  <tr>
                    <td>
                    <a href="<c&#58;url value="/shop/viewCategory.do?categoryId=FISH"/>">
                    <img border="0" src="../images/fish_icon.gif" /></a>
                    </td>
                  </tr>
                  <tr>
                    <td>
                    <a href="<c&#58;url value="/shop/viewCategory.do?categoryId=DOGS"/>">
                    <img border="0" src="../images/dogs_icon.gif" /></a>
                    </td>
                  </tr>
                  <tr>
                    <td>
                    <a href="<c&#58;url value="/shop/viewCategory.do?categoryId=CATS"/>">
                    <img border="0" src="../images/cats_icon.gif" /></a>
                    </td>
                  </tr>
                  <tr>
                    <td>
                    <a href="<c&#58;url value="/shop/viewCategory.do?categoryId=REPTILES"/>">
                    <img border="0" src="../images/reptiles_icon.gif" /></a>
                    </td>
                  </tr>
                  <tr>
                    <td>
                    <a href="<c&#58;url value="/shop/viewCategory.do?categoryId=BIRDS"/>">
                    <img border="0" src="../images/birds_icon.gif" /></a>
                    </td>
                  </tr>
    
                  </tbody>
                 </table>
    
               </td>
              <td align="center" bgcolor="white" height="300" width="100%">
    
              <!-- MAIN IMAGE -->
    
              <map name="estoremap"><area alt="Birds" coords="72,2,280,250" href="viewCategory.do?categoryId=BIRDS" shape="RECT" />
              <area alt="Fish" coords="2,180,72,250" href="viewCategory.do?categoryId=FISH" shape="RECT" />
              <area alt="Dogs" coords="60,250,130,320" href="viewCategory.do?categoryId=DOGS" shape="RECT" />
              <area alt="Reptiles" coords="140,270,210,340" href="viewCategory.do?categoryId=REPTILES" shape="RECT" />
              <area alt="Cats" coords="225,240,295,310" href="viewCategory.do?categoryId=CATS" shape="RECT" />
              <area alt="Birds" coords="280,180,350,250" href="viewCategory.do?categoryId=BIRDS" shape="RECT" /></map>
              <img border="0" height="355" src="../images/splash.gif" align="center" usemap="#estoremap" width="350" />
              </td></tr></tbody></table></td></tr>
    
            </tbody>
            </table>
    
    <%@ include file="IncludeBanner.jsp" %>
    
    <%@ include file="IncludeBottom.jsp" %>
    Can anybody guide me where are things going wrong

  • #2
    Please do not crosspost. I have deleted the other post in the architecture forum.

    Thanks,
    Rod

    Comment

    Working...
    X