Robert Kromkamp wrote:
Hi,
I'm trying to upload an image with Cocoon. But when i'm trying to read the parameters of the file in my Action it seems to be an String. What did I do wrong?
I've the following form:
addresidence.xml =================== <form action="addresidence.html" enctype="multipart/form-data"> <tr> <td> <input type="file" name="uploadfile" size="50"/> <input type="submit"/> </td> </tr> </form> ===================
web.xml =================== <init-param> <param-name>enable-uploads</param-name> <param-value>true</param-value> </init-param> ===================
myAction.java (extends AbstractXMLFormAction implements FormListener) =================== import org.apache.cocoon.acting.AbstractXMLFormAction; import org.apache.cocoon.components.xmlform.Form; import org.apache.cocoon.components.xmlform.FormListener; import org.apache.cocoon.servlet.multipart.Part;
.....
HashMap parameters = new HashMap();
Enumeration parametersEnum = getRequest().getParameterNames(); System.out.println("Voor de while"); while( parametersEnum.hasMoreElements() ){ String name = (String)parametersEnum.nextElement(); Object value = getRequest().getParameter( name );
No, getParameter returns a String. you need:
Object value = getRequest().get(name);
System.out.println("Voor instanceof"); System.out.println("instance of: "+value.getClass().getName()); System.out.println("instance package: "+value.getClass().getPackage()); System.out.println("instance to string: "+value.toString()); if (value instanceof Part) { System.out.println("Part"); } parameters.put( name, value ); }
===================
sitemap.xmap ===================
<map:pipeline> <map:match pattern=""> <map:redirect-to uri="overview.html"/> </map:match>
<map:match pattern="wml/"> <map:redirect-to uri="../overview.wml"/> </map:match>
<map:match pattern="overview.html"> <map:read src="overview.html"/> </map:match>
<map:match pattern="overview.wml"> <map:read src="overview.wml"/> </map:match>
<map:match pattern="img/*.gif"> <map:read src="img/{1}.gif" mime-type="image/gif" /> </map:match>
<map:match pattern="img/*.jpg"> <map:read src="img/{1}.jpg" mime-type="image/jpg" /> </map:match>
<map:match pattern="stylesheets/css/*.css"> <map:read src="stylesheets/css/{1}.css" mime-type="text/css " /> </map:match> </map:pipeline>
<map:pipeline> <map:match pattern="addresidence.*"> <map:act type="request"> <map:parameter name="parameters" value="true"/> <map:act type="MyAction"> <map:generate src="upload.html"/> <map:serialize type="html" label="debug"/> </map:act> </map:act> </map:match> </map:pipeline> ===================
I get the following output of my program: ----- Voor de while Voor instanceof instance of: java.lang.String instance package: package java.lang, Java Platform API Specification, version 1.4 instance to string: C:\jakarta-tomcat-4.1.12\work\Standalone\localhost\forms\cocoon-files\upload -dir\group-logo.gif -----
As you can see it's an instance of a String, but I expected an instance of a Part. Can someone explain this?
When I look in the directory C:\jakarta-tomcat-4.1.12\work\Standalone\localhost\forms\cocoon-files\upload -dir\ there's no file available. What do I do wrong? Has it something to with AbstractXMLFormAction? I'm deploying under tomcat. Do I've to change some settings of it?
Many thanks for your time!
Kind regards, Robert Kromkamp
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
