*
The moose likes Struts and the fly likes java.lang.ClassCastException: org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFil Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "java.lang.ClassCastException: org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFil" Watch "java.lang.ClassCastException: org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFil" New topic
Author

java.lang.ClassCastException: org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFil

Kunal Bhatia
Greenhorn

Joined: Aug 28, 2009
Posts: 11
Dear All,

Iam using a File Upload Control in my jsp and have created an action against it...I'm trying to save the filePath in the database with the help of getHibernateTemplate().saveOrUpdate() method..whic is throwing this exception: -

exception

javax.servlet.ServletException: org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFile
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:520)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:427)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

java.lang.ClassCastException: org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFile
org.hibernate.type.StringType.toString(StringType.java:44)
org.hibernate.type.NullableType.toLoggableString(NullableType.java:218)
org.hibernate.pretty.Printer.toString(Printer.java:53)
org.hibernate.pretty.Printer.toString(Printer.java:90)
org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:97)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:693)
com.EMS.EmployeeCRUD.dao.EmpDAOImpl.saveOrUpdate(EmpDAOImpl.java:22)
com.EMS.EmployeeCRUD.action.AddEmployeeAction.execute(AddEmployeeAction.java:54)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

In order to clear all the doubts...iam using hsqldb as database......

public class AddEmployeeAction extends Action {

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response){
System.out.println("Welcome to add Employee");
FileOutputStream outputStream = null;
FormFile myFile = null;

AddUpdateEmployeeForm frm = (AddUpdateEmployeeForm)form;
Employee emp = new Employee();
String usrname = frm.getUsername();
myFile = frm.getMyFile();
System.out.println("File is-->" + myFile);
try{
String fileName = myFile.getFileName();
String filePath = getServlet().getServletContext().getRealPath("/")+"fileAttachment"+"\\";
File fileToCreate = new File(filePath,fileName);
outputStream =new FileOutputStream(fileToCreate);
outputStream.write(myFile.getFileData());
}catch(Exception e){
System.out.println("Exception-->" + e);
}

System.out.println("UserName-->" + usrname);
System.out.println("Address-->" + frm.getAddress());
BeanUtils.copyProperties(frm, emp);
EmpDAO empDao = (EmpDAO)BeanFinder.getBean(BeanFinder.getContext(request),"empDao");
empDao.saveOrUpdate(emp);
System.out.println("Hello World----");
return mapping.findForward("success");

}

}

DAO Method
public void saveOrUpdate(Employee emp){
try{
System.out.println("Welcome to Save or Update DAO Method");
getHibernateTemplate().saveOrUpdate(emp);
}catch(RuntimeException e){
throw(e);
}
}
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Welcome to javaranch,
Please put code tag for your code, that will help to understand code easily....


Thanks,
Shailesh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java.lang.ClassCastException: org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFil