• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ActionForm class

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you be more specific, maybe post the code which do the problem.
 
Sree Kumari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At least you could try to import edu.LookupForm;
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sree Kumari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My context is
c:\
tomcat
webapps\struts-test
index.jsp, web-inf
|
struts-config.xml,web.xml,struts-html.tld,lib,classes
|
edu
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

your WEB-INF shuldn't be web-inf
 
vijaya bharath
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

your WEB-INF shuldn't be web-inf
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How you are compiling these classes?
 
Fallen Angel
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ------
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have struts.jar in classpath? Why are you putting source into WEB-INF/classes?
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have an import statement for the fully qualified class name for LookupForm?
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
show your web.xml and struts-config.xml to us.
there may be some errors there.
 
naraharirao mocherla
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic