This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes java.lang.IllegalArgumentException: Cannot invoke UploadForm.setUplaod - argument type mismatch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "java.lang.IllegalArgumentException: Cannot invoke UploadForm.setUplaod - argument type mismatch" Watch "java.lang.IllegalArgumentException: Cannot invoke UploadForm.setUplaod - argument type mismatch" New topic
Author

java.lang.IllegalArgumentException: Cannot invoke UploadForm.setUplaod - argument type mismatch

Degree DegreeS
Greenhorn

Joined: Jan 16, 2010
Posts: 2
Hi

i want to uplaod Excel sheet data into database with POI features in struts 1.2 but it giving the error.

at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1778)
at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:1759)
at org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1648)
at org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:1677)
at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1022)
at org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:811)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:467)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:818)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:194)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)


Please help me
Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Not really giving us much to go on.

Without any actual information, it looks like your form definition doesn't match what's coming in from the request.

I would suggest fixing the spelling of "setUpload", though.
Degree DegreeS
Greenhorn

Joined: Jan 16, 2010
Posts: 2
Hi

David , Thanks for your response !!!

<code>
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{

FileInputStream fstream;
File fileTowrite, fileToCreate;
String currenttime, filepath,filepath1;
DataAccess dao = new DataAccess();
totalCnt = 0;
successCnt = 0;
errorCnt = 0;
UploadForm myForm = (UploadForm)form;
UploadDataDB uploadData = new UploadDataDB();
ActionErrors errors = new ActionErrors();
ActionMessages am = new ActionMessages();



String contentType = myForm.getUploadContentType();
String fileName = myForm.getUploadFileName();
System.out.println("contentType: " + contentType);
System.out.println("File Name: " + fileName);
try {



filepath = servlet.getServletContext().getRealPath("/")+ "upload";

// trying to copy the file using copyFile option but always I am getting the error here only please suggest me

fileToCreate = new File(filepath,myForm.getUploadFileName());
FileUtils.copyFile(myForm.getUplaod(),fileToCreate);

fstream = new FileInputStream(fileToCreate);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));

stringAppend = new StringBuilder();
StringBuilder stringAppend1 = new StringBuilder();
stringAppend1.append("\n***********************************************************************\n\n");

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
currenttime = dateFormat.format(date);
stringAppend1 = stringAppend1.append(currenttime + " Skipped Lines are : " + "\n\n");

logger.debug("------Before getting the connection from database-----");
logger.debug("------After getting the connection from database----");


POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(fileToCreate));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row;
int rows; // No of rows

rows = sheet.getPhysicalNumberOfRows();
int cols = 0; // No of columns

int tmp = 0;

// This trick ensures that we get the data properly even if it doesn't start from first few rows
for (int i = 0; i < 10 || i < rows; i++) {
row = sheet.getRow(i);
if (row != null) {

tmp = sheet.getRow(i).getPhysicalNumberOfCells();
if (tmp > cols) {
cols = tmp;
}
System.out.println("ROWS>>>>>>>>"+tmp);
}

}
errorCnt = uploadData.setColumns(rows, cols, sheet);
stringAppend1 = stringAppend1.append(stringAppend);


if (totalCnt != successCnt) {
fileTowrite = new File(filepath, "uploadfile.log");
FileWriter logfile = new FileWriter(fileTowrite, true);
Writer wr = new BufferedWriter(logfile);
wr.write(stringAppend1 + "\n");
wr.close();
}
if (totalCnt == successCnt) {

am.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("Uploaded Successfully"));
//addActionMessage("Uploaded Successfully");
} else if (errorCnt == totalCnt) {
errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("Unable to upload the file because of invalid data.<br/>View the <a target='_new' href='../file?fileName=uploadfile'>log file</a> for more details."));
} else {
errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("Some of the records in the file are not uploaded because of invalid data. <br/>View the <a target='_new' href='../file?fileName=uploadfile'>log file</a> for more details."));
}

return mapping.findForward("success");

} catch (Exception e) {
errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("Please upload file with .xls extension only."));
logger.error("------Exception---" + e.getMessage());
e.printStackTrace();
//return upload();
return mapping.findForward("failure");
} finally {
try {
if (dao != null) {
dao.releaseResources();
}
} catch (Exception e) {
logger.error("------Exception in finally---" + e.getMessage());
return mapping.findForward("failure");
}
}
}

</code>


Hi david I putting my code snippet that would be helpful to you.
Thanks

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Note, however, that this code doesn't actually help: the error occurs before your action is being executed (see the stack trace you posted previously).

I'd also urge you to refactor your action method: it's too long and is responsible for too many things.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.IllegalArgumentException: Cannot invoke UploadForm.setUplaod - argument type mismatch
 
Similar Threads
NullPointerException on Liferay
BeanUtils.populate..
hi friend my system has been giving errror
javax.servlet.jsp.JspException: Cannot create rewrite URL: java.net.MalformedURLException:
request.getParameterValues not working