wood burning stoves 2.0*
The moose likes Struts and the fly likes Need help with java.lang.ClassNotFoundException: org.apache.struts.actions.ForwardAction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Need help with java.lang.ClassNotFoundException: org.apache.struts.actions.ForwardAction" Watch "Need help with java.lang.ClassNotFoundException: org.apache.struts.actions.ForwardAction" New topic
Author

Need help with java.lang.ClassNotFoundException: org.apache.struts.actions.ForwardAction

Deepaks Deshpande
Ranch Hand

Joined: Dec 06, 2007
Posts: 111

Hi all,

I am trying the struts hibernate integration example given at www.mkyong.com. Whenever i am trying to run the web application, i am getting this exception:


My struts-config.xml file is as follows:


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:

Where is the mistake? Where am I going wrong? Please help me.
Thank you.


Regards,
Deepak

Sumit Patil
Ranch Hand

Joined: May 25, 2009
Posts: 296

I am not sure about this, but have you tried using <html:link>? Once again, this is a wild guess...


Thanks & Regards, Sumeet
SCJP 1.4, SCWCD 5, LinkedIn Profile
Swetha Bhagavathula
Ranch Hand

Joined: Jan 04, 2011
Posts: 112

Deepaks Deshpande wrote:

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...








SCJP5
Swetha Bhagavathula
Ranch Hand

Joined: Jan 04, 2011
Posts: 112

@Deepak..
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 correct me if I am wrong...

Deepaks Deshpande
Ranch Hand

Joined: Dec 06, 2007
Posts: 111

@Shwetha
Do you mean to say all the problem with this exception is being caused by the <c:redirect /> tag in the index.jsp page?
Swetha Bhagavathula
Ranch Hand

Joined: Jan 04, 2011
Posts: 112

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..
Swetha Bhagavathula
Ranch Hand

Joined: Jan 04, 2011
Posts: 112

@Deepak..
please check this , I think you have used without setting the JAR file (struts-extras-(version).jar)

I am not sure of my answer ,please let me know ,so that I can learn and correct myself
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help with java.lang.ClassNotFoundException: org.apache.struts.actions.ForwardAction