• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help Please Cannot cast from ActionForm to StudentForm

 
student study
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
 
Lasse Koskela
author
Sheriff
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.
 
somkiat puisungnoen
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...
 
nash avin
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
 
venkat penmatsa
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>









 
Mohan rvscas
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic