I am having problems with the FileUpload in struts. I am uploading an Excel File through browser and sending to Struts Action Class, handling it with FormFile. I am casting this FormFile to FileInputStream which is working fine.
But when I am deleting some of the rows in that excel file and uploading it again its giving me a ClassCastException when converting the Form File to FileInputStream. I have no idea y its happening like this. Can any one help me with this? Thanks Here is the error I am getting root cause java.lang.ClassCastException at rcsa.struts.ExcelFileUpload.execute(ExcelFileUpload.java:48) at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) at javax.servlet.http.HttpServlet.service(HttpServlet.java:716) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:198) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:595) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:432) ****************************************************************************************** Here is the code import java.io.*; import javax.servlet.ServletException; import javax.servlet.http.*; import org.apache.struts.upload.FormFile; import org.apache.struts.action.*; import rcsa.poi.RcsaPOIEventListner; import rcsa.exceptions.RcsaException; import rcsa.dao.OpRiskSSheet; import rcsa.misc.ErrorHandler; public class ExcelFileUpload extends Action { // --------------------------------------------------------- Instance Variables String target; // --------------------------------------------------------- Methods /** * Method execute * @param mapping * @param form * @param request * @param response * @return ActionForward */ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, RcsaException{ ActionMessages errors = new ActionMessages(); if(form != null){ ExcelFileUploadForm excelForm = (ExcelFileUploadForm) form; FormFile formFile = excelForm.getExcelFile(); InputStream in = (InputStream) formFile.getInputStream(); FileInputStream fin = (FileInputStream) in; errors.clear(); RcsaPOIEventListner.readExcelStream(fin); //errors = new ErrorHandler(opSheet, errors).checkErrors(); if(errors.isEmpty()){ target = "success"; }else{ target = "failure"; } }else{ errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("UNABLE TO LOCATE THE EXCEL FILE", false)); target = "failure"; } saveErrors(request, errors); return mapping.findForward(target); } } ********************************************************************** import org.apache.struts.validator.ValidatorForm; import org.apache.struts.upload.FormFile; /** [EMAIL PROTECTED] * */ /** *Form bean for File Upload. * */ public class ExcelFileUploadForm extends ValidatorForm{ private FormFile excelFile; /** * @return Returns the theFile. */ public FormFile getExcelFile() { return excelFile; } /** * @param theFile The FormFile to set. */ public void setExcelFile(FormFile excelFile) { this.excelFile = excelFile; } } -- View this message in context: http://www.nabble.com/ClassCast-Exception-for-ExcelFile-Upload-tf3659580.html#a10225552 Sent from the Struts - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]