• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Help Please Cannot cast from ActionForm to StudentForm

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic