Hi Marli, No, you should be able to use the struts utils in your servlet. You will have to manually create a FormFile however. Look at the source for the html:file tag.
Jon. -----Original Message----- From: Marli Satyadi [mailto:[EMAIL PROTECTED]] Sent: 30 November 2001 00:13 To: Struts Users Mailing List; 'Struts Users Mailing List' Subject: RE: File Upload Problem. Hi Jon, I am trying to do file upload programatically, not using the browser and I want to use the struts file upload library to achieve this. So I want to try the library first by writing a simple html file and a simple servlet for testing. Does this mean that I cannot use the upload code if I don't use struts tags ?? Thanks. Marli. At 09:42 AM 11/29/2001 +0000, Jon.Ridgway wrote: >Hi Marli, > >I might be missing something here, but you don't appear to be using struts. >Are you aware that there is a strurs tag for file upload? Have a look at the >struts examples. > >Jon. > >-----Original Message----- >From: Marli Satyadi [mailto:[EMAIL PROTECTED]] >Sent: 29 November 2001 01:23 >To: [EMAIL PROTECTED] >Subject: File Upload Problem. > >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]> > >-- >To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> >For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>