If you don't parse the stream, you will hava problems as there are some
informations before the actual file. For example you will get the
content-type of the document. One good solution however is to use
JspSmartUpload from http://www.jspsmart.com/ which is free and does all the
parsing. It includes samples to teach you how to use it.

Regards.
----- Original Message -----
From: "Sohaila Roberts" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, September 17, 2001 5:44 PM
Subject: InputStreams


> Hi, I know there is an example of uploading files via servlets in the
> o'reilly servlet programming book, I was just wondering what would happen
> if i had the following html page
>
> <FORM ACTION="UploadServlet" METHOD=POST>
> Select the file to upload <INPUT TYPE=FILE NAME=filename><br>
> <INPUT TYPE=SUBMIT>
> </FORM>
>
> and UploadServlet contained the following
>
> public void doPost(HttpServletRequest req, HttpServletResponse resp)
>     throws ServletException, IOException
> {
>         String filename = req.getInputStream().getParameter("filename");
>         File f = new File(filename);
>         try {
>                 FileInputStream fin =
>                         (FileInputStream)req.getInputStream();
>                 FileOutputStream fout =
>                         new FileOutputStream(f);
>                 int ch;
>                 while((ch = fin.read())!=-1) {
>                         fout.write(ch);
>                 }
>                 fin.close();
>                 fout.close();
>                 //stick f in database or whereever..
>         } catch (IOException e) {}
> }
>
> would this work to upload a file such as .doc or .wpd or .sdw type files
> or any other files for that matter?
>
>
> Thanks!
> Sohaila
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to