Lance
saw this on nabble..
ExcelFileUploadForm excelForm = (ExcelFileUploadForm) form;
FormFile formFile = excelForm.getExcelFile();
InputStream in = (InputStream) formFile.getInputStream();
FileInputStream fin = new (FileInputStream( in ) );
Does this help?
M--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed. If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy. Thank you.
----- Original Message -----
From: "Lance" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Monday, April 30, 2007 9:21 AM
Subject: Re: ClassCast Exception for ExcelFile Upload
I think this is your problem... FileInputStream fin = (FileInputStream) in;
Do you need to do this?
Can you do RcsaPOIEventListner.readExcelStream(in);
The input stream is coming from the request which is not necessarily saved
to disk / read from a FileInputStream.
Kirthi wrote:
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;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]