Sohalia,
It won't work. It won't compile b/c you cannot cast
javax.servlet.ServletInputStream to java.io.FileInputStream and there is no
getParameter method on an InputStream.  Even if you fixed these compile
errors, your code does not handle the boundary lines between the multiple
parts of the message.  I'd suggest that you try your code out and see for
yourself.  If it were that easy, most people would write it themselves
rather than use a package such as Jason Hunter's com.oreilly.servlet package.

-Richard




At 01:14 PM 9/17/01 -02-30, you wrote:
>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

___________________________________________________________________________
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