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://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> --> [b] <action path="/shop/viewCategory" />[/b] <!-- <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> [b]<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>[/b] </struts-config>
In struts.config I have added the </controller> & <plug-in>
My web.xml is as follows
web.xml:-
Please note that here my <servlet-name> is actionCode:<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://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 "{servlet-name}-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> [b]<servlet-name>action</servlet-name>[/b] <!-- <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>
Now I have prepared action-servlet.xml
My action-servlet.xml is as follows:-
All other files are not changed.Code:<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://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> [b] <bean name="/shop/viewCategory" class="org.springframework.samples.jpetstore.web.spring.ViewCategoryController" > <property name="petStore" ref="petStore"/> </bean>[/b] <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>
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
My index.jsp in struts folder is as follows:-Code:org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named '/shop/viewCategory' must be of type [org.apache.struts.action.Action], but was actually of type [org.springframework.samples.jpetstore.web.spring.ViewCategoryController] org.springframework.beans.factory.support.AbstractBeanFactory.checkMergedBeanDefinition(AbstractBeanFactory.java:749) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:151) org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:540) org.springframework.web.struts.DelegatingRequestProcessor.getDelegateAction(DelegatingRequestProcessor.java:161) org.springframework.web.struts.DelegatingRequestProcessor.processActionCreate(DelegatingRequestProcessor.java:142) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:220) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164) org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397) javax.servlet.http.HttpServlet.service(HttpServlet.java:689) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Can anybody guide me where are things going wrongCode:<%@ 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:if test="${!empty accountForm.account}"> <b><i><font size="2" color="BLACK">Welcome <c:out value="${accountForm.account.firstName}"/>!</font></i></b> </c:if> </td> </tr> <tr> <td> <a href="<c:url value="/shop/viewCategory.do?categoryId=FISH"/>"> <img border="0" src="../images/fish_icon.gif" /></a> </td> </tr> <tr> <td> <a href="<c:url value="/shop/viewCategory.do?categoryId=DOGS"/>"> <img border="0" src="../images/dogs_icon.gif" /></a> </td> </tr> <tr> <td> <a href="<c:url value="/shop/viewCategory.do?categoryId=CATS"/>"> <img border="0" src="../images/cats_icon.gif" /></a> </td> </tr> <tr> <td> <a href="<c:url value="/shop/viewCategory.do?categoryId=REPTILES"/>"> <img border="0" src="../images/reptiles_icon.gif" /></a> </td> </tr> <tr> <td> <a href="<c: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" %>


Reply With Quote