• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Help Please Cannot cast from ActionForm to StudentForm

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am getting this Eroor


Cannot cast from ActionForm to StudentForm


public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
StudentService service = new StudentService();
StudentForm studentForm = (StudentForm) form; //Error
StudentDTO studentDTO = new StudentDTO();
BeanUtils.copyProperties( studentDTO, studentForm );
service.insertStudent( studentDTO );
request.setAttribute("employee",studentDTO);
return (mapping.findForward("success"));
}

I have extended Action in StudentForm class.


Any help would be greatly appreciated.

Thanks
AS
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by student study:
I have extended Action in StudentForm class.


You'll have to extend ActionForm, not Action.

By the way, since "student study" is not in compliance with our naming policy, I'll have to ask you to change your display name into something valid. The display name must be your real name or a fake name that looks real and isn't otherwise obviously fake.
Thanks.
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please post your struts-config.xml file.


AND


please check form type of this action in config file.

may be incorrect...
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Thanks a lot for the responses.I will surely work that out.Must be a trivial issue.

Thanks again
AS
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , I m getting Cannot cast from ActionForm to BankController error even though i imported the action class , please help me ASAP.

public class BankController extends Action{

public ActionForward execute( ActionMapping mapping,ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception{

LoginForm l=(LoginForm)form;
BankController b=(BankController)form;

return null;
}
}

this is my struts.config,xml



<action
attribute="Balence"
input="Banklogin.jsp" name="Balence" path="/BankController" scope="request"
type="edu.action.BankController">
<set-property property="cancellable" value="true" />
<forward name="failure" path="/failure.jsp" />
<forward name="success" path="/welcome.jsp" />
</action>









 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi venkat penmatsa,

I think your form-bean tag only mapped with LoginForm class.

and also for a request should have only one form-bean attribute that means either LoginForm bean or BankController bean

but you are casting the form object for two classes as you posted like this.


LoginForm l=(LoginForm)form;
BankController b=(BankController)form;



just put any one statement. Relevant what you mapped with the form-bean attribute.
 
and POOF! You're gone! But look, this tiny ad is still here:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic