File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes ActionForm class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ActionForm class " Watch "ActionForm class " New topic
Author

ActionForm class

Sree Kumari
Ranch Hand

Joined: Aug 16, 2005
Posts: 50
I am new to struts for doing a simple Iam unable to compile the Action class(controller).I am unable to get the Action Form class in it.Any body please suggest a method
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Could you be more specific, maybe post the code which do the problem.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Sree Kumari
Ranch Hand

Joined: Aug 16, 2005
Posts: 50
This is from the view
<html:form action="/Lookup" name="lookupForm" type="edu.LookupForm">


package edu;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class LookupForm extends ActionForm

{private String symbol=null;

public String getSymbol()
{return (symbol);
}

public void setSymbol(String symbol)
{this.symbol=symbol;
}

public void reset(ActionMapping mapping,HttpServletRequest req)
{

this.symbol=null;
}
}




package edu;
import java.io.IOException;
import javax.servlet.ServletException;
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.ActionMapping;
import org.apache.struts.action.ActionForward;


public class LookupAction extends Action
{
protected Double getQuote(String symbol)
{

if(symbol.equalsIgnoreCase("SUNW"))
{
return new Double(25.00);
}
return null;
}

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
Double price=null;
String target=new String("success");
if(form!=null)

{
LookupForm lookupForm=(LookupForm)form;//At this point while compilation shows cannot resolve symbol
String symbol=lookupForm.getSymbol();
price=getQuote(symbol);
}
if(price==null)
{target=new String("failure");
}
else
{request.setAttribute("PRICE",price);
}
return(mapping.findForward(target));
}
}
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
At least you could try to import edu.LookupForm;
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

It looks like they are in the same package, David.

What symbol can't be resolved? Java is probably not complaining about your "symbol" variable, by the way. The error message usually says what symbol it does not like. What is it?


A good workman is known by his tools.
Sree Kumari
Ranch Hand

Joined: Aug 16, 2005
Posts: 50
it is not about the symbol variable in this program.it shows as if it can't resolve the LookupForm in the casting LookupForm lookupForm=(LookupForm)form.Since both LookupAction and LookupForm are of the same package is it necessary to import edu.
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
And that is the problem, because both classes are in the same package, there should be no problem with the import. Aren't your problem in directory structure on HDD?
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

I wondered if the ActionMapping from struts-config wasn't defined with the proper form but I think that would cause a ClassCastException at runtime.

The error you are stating sounds like a compilation issue. If the two classes are in the same package and in the correct folder structure, the two classes should have no problems finding each other. So, as Dave asked, are you sure you've got the directory structure correct?
Fallen Angel
Greenhorn

Joined: Sep 07, 2005
Posts: 5
Hi,

Im reasonably new to Struts myself so excuse me if am off the mark here.

It seems as though the complier doesn�t like the way you are passing the actionform to a its own datatype.considering that you only apparently use it to parse a form field - perhaps the following might work

String symbol =((LookupForm)form).getSymbol();
Sree Kumari
Ranch Hand

Joined: Aug 16, 2005
Posts: 50
My context is
c:\
tomcat
webapps\struts-test
index.jsp, web-inf
|
struts-config.xml,web.xml,struts-html.tld,lib,classes
|
edu
vijaya bharath
Ranch Hand

Joined: Jun 10, 2005
Posts: 66
Hi,

your WEB-INF shuldn't be web-inf


Regards,<br />Vijaya Bharath.<br />SCJP1.4 <br />SCWCD5.0
vijaya bharath
Ranch Hand

Joined: Jun 10, 2005
Posts: 66
Hi,

your WEB-INF shuldn't be web-inf
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
How you are compiling these classes?
Fallen Angel
Greenhorn

Joined: Sep 07, 2005
Posts: 5
im telling you - you need to take out the bit of code in your action where you pass the form to itself(the bit that fails) and use the code i suggested. I do the same thing for the address search on www.courtservice.gov.uk and it works fine.
Sree Kumari
Ranch Hand

Joined: Aug 16, 2005
Posts: 50
No way, I tried another example the same error repeats if I am trying to access the same ActionForm class inside the action class.I have copied struts.jar into my WEB-INF's lib also
I compile it from the command prompt
c:\tomcat\webapps\struts-test\WEB-INF\classes\edu>javac ------
martin jose
Greenhorn

Joined: Aug 10, 2005
Posts: 9
Sree Vidya,

Better you try to create seperate packages for the form and action. Just create two folders,(say action, form) in the WEB-INF/classes/edu folder. Begin your action class with

package edu.action;

and your form with

package edu.form;

I your Action class import package edu.form.*. When you compile the action class you will have to include classes/edu/form folder in the classpath.Hope it will work. I am sorry if it sounds silly.

Regards
Martin
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Do you have struts.jar in classpath? Why are you putting source into WEB-INF/classes?
naraharirao mocherla
Ranch Hand

Joined: Aug 16, 2005
Posts: 45
Hi everyone,

Can Anyone plase let me know what could be the problem for this question??

I'm also getting the same problem.I've included struts.jar in my classpath.


when I'm compiling LookupAction.java I'm getting the compilation errors .
1. cant resolve symbol LookupForm .
2.can't resolve symbol "symbol" which is an instance variable in LookupForm.java

thanks
Narahari
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Do you have an import statement for the fully qualified class name for LookupForm?


Merrill
Consultant, Sima Solutions
sun cheng
Greenhorn

Joined: Jun 02, 2006
Posts: 17
show your web.xml and struts-config.xml to us.
there may be some errors there.
naraharirao mocherla
Ranch Hand

Joined: Aug 16, 2005
Posts: 45
Hi Merrill and sun.
The code is working now.It got compiled.That was the classpath problem I think.I fixed it.But now I'm getting another error while running the application.

I have Index.jsp and quote.jsp as views.LookupForm and lookupAction classes and web.xml and struts-config.xml.I've copied struts-html.tld file from "lib" directory to my application's (wroxapp) WEB-INF directory.
My error is

index.jsp

web.xml


The error is with "taglib-uri" i think.The example is from wrox book
"Prfessional Jakarta Struts 1.1".
can anyone please help??

Thanks
Narahari
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I am not sure about your latest post...but your compile error seems to be a common issue with people new to Java. You should run javac from the root directory of your source. You are using the package edu, so your source files are in a directory named edu. You should run javac from the directory that contains edu, NOT the edu directory. Something like this:

cd \tomcat\webapps\struts-test\WEB-INF\classes\
javac .\edu\*.java

Edit...after posting I realized that the previous post was not from the original poster and that the original post that my post was aimed at was an old one...oh well.

- Brent
[ June 08, 2006: Message edited by: Brent Sterling ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In version 1.2.9 of Struts, the <html:form> tag no longer accepts a name or type attribute. When you specify the action attribute, it looks up the action mapping in struts-config.xml and uses the name and type you provided there. Just remove these attributes from your tag and it should work fine.
[ June 08, 2006: Message edited by: Merrill Higginson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ActionForm class