• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problem in file Upload using struts html:file tag ILLegal Argument Exception

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am stuck with this since few days...Having the same issue

I have to use the property in my jsp which is of type "org.apache.struts.upload.FormFile" to upload a file .Like this
<html:file property="primaryFile" maxlength="250" />

In my form I declared it as
private FormFile primaryFile ;
public void setPrimaryFile(FormFile primaryFile) {
this.primaryFile = primaryFile;
}
public FormFile getPrimaryFile() {
return primaryFile;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
this.primaryFile=null ;
}

I am getting this exception

[5/10/06 10:30:33:322 PDT] 7ff3d4d6 WebGroup E SRVE0026E: [Servlet Error]-[BeanUtils.populate]: java.lang.IllegalArgumentException: Cannot invoke com.strykercorp.e3s.stellent.forms.CheckInNewForm.setPrimaryFile - argument type mismatch
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:493)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:816)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1049)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:600)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:201)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:125)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:286)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:624)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:448)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:912)
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you specify enctype="multipart/form-data" in your <html:form> tag? If not, that's the problem.
 
Anita Ganga
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have my html:form defined like this.

<html:html>

<script language="javascript">
//this does not validate drop downs!
function validate(frm) {
var boolValid = true;
document.getElementById('checkinNew').elements['command'].value='Submit';
return boolValid;
}


</script>

<html:form styleId="checkinNew" method="get" enctype="multipart/form-data" action="/checkInNew" onsubmit="return validate(document.getElementById('checkinNew'));">
<html:hidden property="command" value=""/>
<table width="760" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="200">
<div align="right">File <font color="#FF0000">*</font></div></td>
<td> </td>
<td><html:file property="primaryFile" maxlength="250" />
</td>
</tr>
<tr>
<td width="50%" align="right"><html:reset property="reset" >Reset</html:reset>
</td>
<td width="5"> </td>
<td width="50%"><html:submit property="submit" >Check In >></html:submit></td>
</tr>
</table>
</html:form>

</html:html>
 
Anita Ganga
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Appreciate any thoughts...


My struts config looks like this...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<!-- Form Beans -->
<form-beans>
<form-bean name="checkInNewForm" type="com.strykercorp.e3s.stellent.forms.CheckInNewForm">
</form-bean>
</form-beans>
<!-- Action Mappings -->
<action-mappings>
<action name="checkInNewForm" path="/checkInNew" scope="request" type="com.strykercorp.e3s.stellent.actions.CheckInNewAction">
<forward name="success" path="/pages/checkin_new_form.jsp">
</forward>
<forward name="target" path="/pages/checkinnew_results.jsp">
</forward>
</action>
</action-mappings>
</struts-config>
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For a file upload, you must either omit the method attribute entirely or specify method="POST" in the <html:form> tag. The default method is post. "get" is not an option for file uploads.
 
Anita Ganga
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I did'nt specify any get /post earlier but I was getting the error pasted below. So I tried changing it to get and this error was gone and Illegal Argument Exception showed up.

Even now I did try changing it to post it gave me the same error. I have commons-io-1.1.jar and commons-fileupload-1.1.jar under WEB-INF/lib

Appreciate any insight of why thatis happening

SRVE0026E: [Servlet Error]-[org/apache/commons/io/output/DeferredFileOutputStream]: java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
at org.apache.commons.fileupload.DefaultFileItemFactory.createItem(DefaultFileItemFactory.java:102)
at org.apache.commons.fileupload.FileUploadBase.createItem(FileUploadBase.java:488)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:359)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:266)
at org.apache.struts.upload.CommonsMultipartRequestHandler.handleRequest(CommonsMultipartRequestHandler.java:193)
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:442)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:816)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1049)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:600)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:201)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:125)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:286)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:116)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:186)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:624)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:448)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:912
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's something odd going on here. Struts doesn't even use commons-io-1.1.jar. The DeferredFileOutputStream class that struts needs to use is in commons-fileupload.jar and it's fully qualified name is org.apache.commons.fileupload.DeferredFileOutputStream.

First of all, verify that all of the commons-xxx jar files that you have in your /lib directory are exactly the same ones that came with the download of the version of Struts that you're using. They'll be in the /lib directory when you unzip it. Then try running the application again and see if the error persists.

If this still doesn't work, I'd try removing commons-io.jar, since struts doesn't use it.
 
Anita Ganga
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried all different things u mentioned.It doesnot work what so ever.
Any thoughts appreciated.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still think this is happening because your jar files are messed up.

Another thing that may be happening is that you may have another version of one or more of these jar files being loaded in another Class Loader. If you're using Tomcat, search for another version of one of these jar files in either <tomcat root>/common/lib <tomcat root>/server/lib, or <tomcat root>/shared/lib. If you find one, remove it and try again.

If this still doesn't fix it, try this:

Create an entirely new Web Project starting with struts-blank.war. I don't know what IDE you're using (if any) but make sure you have a completely clean project with nothing except the items in struts-blank.war.

Then copy all your resources into this new project, including your struts-config.exe file, but don't touch the jar files in WEB-INF/lib and try again.

Let me know how things go.
 
Anita Ganga
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Merrill that worked.
actually i am using WebSphere AppServer and in my lib\ext I had a common1.1 jar for fileupload and it was picking that up.
I deleted that from there and it works fine now..

Thank you for the responses!!!
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"MCA Gang",

Welcome to JavaRanch. We don't have many rules here but we do have a naming policy that we strictly adhere to. Please re-read this naming convention and change your display name in order to comply. Thanks in advance.
 
There is no "i" in denial. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic