Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 13th, 2004, 06:46 AM
Authorized User
 
Join Date: Jul 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sherbir
Default URGENT : Jakarta Commons FileUpload error

Hi fellas,
I am using the Jakarta commons fileupload jar to write an upload servlet.

I have created an html file where I upload a file as follows :
<form name="upload_form" enctype="multipart-form/data" method="post" action="servlet/UploadServlet2">
<center>

Please choose a file to upload <input type="file" name="upload_file">

<input type="submit" name="bttn_submit" value="Upload File">

</center>
</form>

On posting this form, I am calling the UploadServlet which has the following code :

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.commons.fileupload.*;

public class UploadServlet2 extends HttpServlet
    {
        protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
        {
            doWork(req, res);
        }

        protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
        {
            doWork(req, res);
        }

        private void doWork(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
        {
            PrintWriter out = res.getWriter();
            out.println(req.toString());
            out.println("page loading");
            out.println(req.getContentType());
            out.println(req.getParameter("myText"));

            boolean isPart = FileUpload.isMultipartContent(req);
            out.println(isPart);
            if(isPart)
            {
                out.println("is multipart");
                DiskFileUpload upload = new DiskFileUpload();
                try
                {
                    List items = upload.parseRequest(req);
                    Iterator it = items.iterator();
                    while(it.hasNext())
                    {
                        FileItem item = (FileItem)it.next();
                        if(!(item.isFormField()))
                        {
                            out.println("success");
                        }
                    }
                }
                catch (FileUploadException e)
                {
                    // TODO Auto-generated catch block
                    System.out.println(e.getMessage());
                    out.println(e.getMessage());
                }
            }
            else
            {
                out.println("file not received");
            }

            out.flush();
            out.close();
        }
    }


But the output that I get is :

org.apache.coyote.tomcat4.CoyoteRequestFacade@7244 ca page loading application/x-www-form-urlencoded null false file not received

WHATS THAT SUPPOSED 2 MEAN ?
Where's the mistake in my code ?

How should I remedy the situation ?

Help needed immediately

Regards,
Sherbir
__________________
Regards,
Sherbir
 
Old August 5th, 2004, 06:56 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

This would be helpful

You can show a Browse and Upload Form buttonusing the following code.

<FORM ENCTYPE="multipart/form-data" method=post action="/utils/FileUploadServlet">
<INPUT TYPE="file" NAME="currentfilename">
<INPUT TYPE="submit" VALUE="upload">
</FORM>

It's easy to use a readily available class, which you can easily embed into your servlet for uploading the file. Download the most widely used File Upload package written by Jason Hunter at this URL http://www.servlets.com/resources/co...let/index.html








Similar Threads
Thread Thread Starter Forum Replies Last Post
Access denied error when using FileUpload Control mii2029 ASP.NET 3.5 Basics 0 October 25th, 2008 05:45 PM
FileUpload "Rooted" error rsearing ASP.NET 2.0 Basics 4 July 20th, 2007 01:17 AM
Commons DBCP error !! sherbir Apache Tomcat 1 September 30th, 2004 04:08 AM
Give me an explanation : Commons DBCP ! sherbir Servlets 1 September 29th, 2004 05:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.