["uploadfile" is the name of the HTML file upload field.]
1. To upload a file, the field needs to be type "file":
<input type="file" name="uploadfile"/>
Sending the filename with:
<input type="text" name="uploadfile">
does not send the file to the server, just a string. You can
immediately see the difference as all browsers show the "Browse"
button when the control is type "file".
2. Cocoon saves the file to the upload directory. To read the file in
Java or XSP:
import org.apache.cocoon.servlet.multipart.Part;
Part part = (Part) request.get("uploadfile");
InputStream inputStream = part.getInputStream();
Then you can use the DocumentBuilder or this method:
DOMParser parser =
manager.lookup(org.apache.excalibur.xml.dom.DOMParser.ROLE);
Document uploadeddoc = parser.parseDocument(inputStream);
Now you can work with an XML Document.
solprovider
On 2/19/08, nanomonk <[EMAIL PROTECTED]> wrote:
> hmm.. I did that. But not like a file...not like a stream... just a text in
> POST parameter.
> pipeline:
> <map:match pattern="upload/myxsp">
> <map:generate src="upload/myxsp.xsp" type="serverpages"/>
>
> <map:serialize type="xml"/>
> </map:match>
> -----
> for test myxsp.html:
> <html>
> <body>
> <form action="http://localhost:80/upload/myxsp" method="post"
> enctype="multipart/form-data">
> File: <input type="text" name="uploadfile">
> <input type="submit"/>
> </body>
> </html>
> -----
> as example... myxsp.xsp:
> <?xml version="1.0"?>
> <xsp:page language="java" xmlns:xsp="http://apache.org/xsp">
> <root>
> <xsp:logic>
> try {
> String foo = request.getParameter("uploadfile");
> System.out.println(foo);
> javax.xml.parsers.DocumentBuilderFactory factory =
> javax.xml.parsers.DocumentBuilderFactory.newInstance();
> javax.xml.parsers.DocumentBuilder builder = factory.newDocumentBuilder();
> org.w3c.dom.Document doc = builder.parse(new
> java.io.ByteArrayInputStream(foo.getBytes()));
> org.w3c.dom.NodeList catlist =
> doc.getDocumentElement().getElementsByTagName("category");
> for (int i = 0; i < catlist.getLength(); i++)
> {
> org.w3c.dom.Node boo = catlist.item(i);
> <xsp:content>
> <xsp:expr>boo</xsp:expr>
> </xsp:content>
> }
> }catch(java.lang.Exception e)
> {
> System.out.print(e.toString());
> }
> </xsp:logic>
> </root>
> </xsp:page>
> -------------
> but.......but I don't need to put xml to parameter.
> I need to take a Content of request. But cocoon's HttpRequest hasn't
> .getContent(). There is getInputStream, but I can't to understand how to use
> that.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]