This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Am I getting this exception because i am trying to access the same resource (add_customer.jsp) using different action paths /AddCustomerPage & /AddCustomer in the <action-mappings/>?
I am trying to redirect to the add_customer.jsp from my index.jsp page the code for which is as follows:
hai,I am not sure of my answer ,but i hope the following..
root cause is it is unable to load "ForwardAction" ,so please check whether you have added " struts-extras-(version).jar" in CLASSPATH? because ForwardAction is built-in Action class and the super class of this class is "org.apache.struts.action.Action" class .and more over the Forward action class is available in "org.apache.struts.actions' package inturn this pachkage is available in struts-extras-(version).jar .so please check this.
one more thing.. you stated:
I am trying to redirect to the add_customer.jsp from my index.jsp page
Generally speaking iit is a bad idea tp place within your jsp pages any direct links to other JSP pages.For one reasong it is not good design decision;the struts-config.xml which is the part of the Controller ,should contain the entire flow of your application.
In Model-View-Controller architecture ,it is the role of the Controller to select the next View.The Controller consits of struts configuration ,theActionServlet,and the actions.Tf you add a link directly to another jsp,,you are violating MVC 2 principles.. where one resource should not communicate with other resouce directly but only should by means of Controller (ActionServlet if struts 1.x - and FilterDispatcher if struts 2.x).and more over struts framework strictly follows MVC2 principles.
for this you need to use ForwardAction class(built-in).
The ForwardAction acts as bridge from currect View(JSp) and teh pages it link to.It uses RequestDispatcher to forward to a specified webresource.It allows you to link to a action insted of directly to jsp.Later,if you need you can theActionMapping in the struts configuration to to a custom one that you write instead of using ForwardAction that struts provide.
To use ForwardAction:
1)use the html:link tag with the action attribut ,add alink to the jsp page that points to the action.
2)Create an action mapping in the struts in the struts configuration file that uses the ForwardAction with the parameter attribute to specify the Jsp path...
I am just quoting an example.. if I am wrong please correct me...
suppose you have a jsp pagethat has a direct link to another jsp page;
you have converted to MVC2 architecture and you wanted to change the html:link to an action.,because you already have a link, so simple change it as follows:
and we need to remove the page attribute and add an action attribute that points to the home action. and create the home action mapping.
the ForwardAction uses the parameter attribute so that you can specify the path.,the paramter here is set to "/index.jsp",which was that page attributte of the html:link tag that was originally set to .Thus, the parameter attribute indicated to whether you want the ForwardAction to forwad..
please check the root cause.. ClassNotFoundException:ForwardAction.. when you use a built-in class, you need to add its corresponding package where the class is residing.. next try to change our code inorder to make it more effcient.... it work when you direclt link one jsp to another,, I am not saying that it doesn't but it is voilating MVC principle and to avoid that I think some where in that ForwardAction class is used and yo didnt add the corresponding package..