Hello,
I was writing some upload code to test the use of MultipartIterator class.
My html code is as follows:
-----------------------------------------
<BODY BGCOLOR="FFFFFF">
<h1> MULTIPART TEST</h1>
<FORM NAME="loadfile"
ACTION="/MDC/servlet/servlet/com.cisco.nm.callhome.servlet.TestServlet"
ENCTYPE='multipart/form-data' METHOD="POST">
CLASS: <INPUT NAME=class TYPE=text VALUE="File">
<br>
COMMAND: <INPUT NAME=cmd TYPE=text VALUE="Add">
<br>
DATA (XML): <textarea name="dataParam" rows=20 cols=80></textarea>
<br>
File Location: <INPUT TYPE=file NAME="uploadfile" SIZE="50">
<br>
<INPUT TYPE=SUBMIT NAME=SUBMIT>
</FORM>
</BODY>
</HTML>
My servlet code is as follows:
-------------------------------------------
protected void doPost(HttpServletRequest req, HttpServletResponse
resp)
throws ServletException, java.io.IOException
{
LogUtil.debug(_Class, " -----> DO POST");
MultipartIterator iter = new MultipartIterator(req, 64*1024,
Integer.MAX_VALUE, "C:/Temp");
MultipartElement elem = null;
while( (elem = iter.getNextElement()) != null )
{
if( elem.isFile() )
{
System.out.println("ELEM is a file");
System.out.println("FILENAME = " + elem.getFileName());
System.out.println("FILE PATH = " +
elem.getFile().getAbsolutePath());
}
else {
System.out.print("NAME = '" + elem.getName() + "'");
System.out.println(". VALUE = '" + elem.getValue() + "'");
//System.out.println(elem.getName() + " = " +
elem.getValue());
}
}
}
When I use my browser to the html file, put some data in the "dataParam"
text area and
hit Submit, I got the following result in Tomcat stdout.log
NAME = 'class'. VALUE = 'File'
NAME = 'cmd'. VALUE = 'Add'
</File>'</AuthTuple>sword>bejo</Password>1663eb7d56063ec67f23be</Checksum>
ELEM is a file
FILENAME = ch-p506-2_enable_callhome.cfg
FILE PATH = C:\Temp\strts4674.tmp
NAME = 'SUBMIT'. VALUE = 'Submit Query'
My question is:
----------------------
* Is there an explanation on why the "dataParam" parameter is not printed out,
or printed out but has the wrong value ?
* I also have written a Java multipart writer to test it, but it looks like
that the file is always
larger by 2 bytes. Isn't the format for multipart request like this:
--Boundary\r\n
content-disposition: form-data; name="blah"; filename="file.txt"\r\n
Content-type: application/octet-stream\r\n
\r\n
Body goes here......
--Boundary--\r\n
Am I correct about the CRLF (\r\n) ? I have read RFC 1867 and RFC 2046
and it looks correct.
Any ideas ?
Thanks in advance.
Marli.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>