Upload client file to servlet

Hi,
 What I would like to accomplish is....
 create web page that allows user to upload a client file (Excel) to servlet for validation.
 so there are 2 parts - web form for upload, servlet to recieve and validate.
 There are 2 issues

 * given the web form and servlet below -  when the file is selected, and submitted I
get back an error page which is shown in Fig3. If I refresh the page, then the servlet responds.
I do not understand why I get the error.

* What do I need to include in my servlet to recieve the file as an IOstream, and to parse the file.
   I do not know where to start. I am using jakarta HSSF to read the excel file, and have this part working
  if reading local file. Just do not know how to setup the servlet to read the input file from client.

Any help would be greatly appreciated...
 
//My Web form - Fig1
<body>
    <FORM NAME=myform METHOD=POST ACTION= 'http://10.10.10.10:8988/Application1-eMos-context-root/mytestservlet' ENCTYPE="multipart/form-data">
       <INPUT TYPE=File SIZE=15 ID=parameterlist NAME=parameterlist>
       <input type="submit" value="Submit">
    </FORM>
</body>

//Servlet - Fig 2

public class myTestServlet extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response) throws ServletException, IOException {response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>myTestServlet</title></head>");
        out.println("<body>");
        out.println("<p>The servlet has received a GET. This is the reply.</p>");
        out.println("</body></html>");
        out.close();
    }
}


//Error - Fig3

 The page cannot be displayed
The page you are looking for cannot be displayed because the address is incorrect.  
--------------------------------------------------------------------------------
Please try the following:
If you typed the page address in the Address bar, check that it is entered correctly.
Open the 10.10.10.10:8988 home page and then look for links to the information you want.
Click  Search to look for information on the Internet.

HTTP 405 - Resource not allowed
Internet Explorer  
RockyFullenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rrzCommented:
See    
http://jakarta.apache.org/commons/fileupload   
You can find many previously ask questions in this java area and the JSP area that will help.  But most of them are for version 1.0  .  You should download 1.1 version now though.  
here is one  example  (look at the last code I posted)
http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21753142.html
0
amol_chaudhariCommented:
hi
on client side default j1.5 package do no allow to upload file.... u hve to use external libraries to upload it....
try the following struts library....
http://apache.secsup.org/dist/struts/binaries/struts-1.2.9-bin.tar.gz
hope this will help
bye
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

RockyFullenAuthor Commented:
rrz,
  I tried your code posted in
http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21753142.html
but get this error

oracle.classloader.util.AnnotatedNoClassDefFoundError:

        Missing class: org.apache.commons.io.FileCleaner

      Dependent class: org.apache.commons.fileupload.disk.DiskFileItem
               Loader: current-workspace-app.web.Application1-eMos-webapp:0.0.0
          Code-Source: /D:/Program Files/Java/jdevstudio1013/jdev/lib/commons-fileupload-1.1.jar
        Configuration: <classpath> in D:\Program Files\Java\jdevstudio1013\jdev\mywork\Application1\eMos\public_html
0
RockyFullenAuthor Commented:
Ok, There is a problem with this solution for those using jakarta fileUpload 1.1.

DiskFileUpload has been deprecated, and replaced with ServletFileUpload.
Not only has it been deprecated, but it will flat out not work.

The new package commons-fileupload-1.1.jar does not include org.apache.commons.io.FileCleaner
So, replace DiskFileUpload with ServletFileUpload to get around this in version 1.1
0
RockyFullenAuthor Commented:
I do not know what I was thinking, rrz's example does not even use DiskFileUpload.
Anyway, I was using a version that did, and thats how I found the problem I mentioned.
I tried your version with a version of the html side I got from somewhere else.

Now that I have the file
List  items = upload.parseRequest(reqContext);
How do I write it to a file?
0
rrzCommented:
from  
http://jakarta.apache.org/commons/fileupload/using.html 
You can use something like the following.
Iterator iter = items.iterator();
while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();
    if (item.isFormField()) {
        processFormField(item);
    } else {
       // you could make some additional checks. like fieldName from client or file size.
        item.write(new File(pathPathYouWant));
    }
}

Let us know if you have any more questions about this.   rrz

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.