commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From michael.la...@hilgmbh.de
Subject Commons Upload: Can not read parameters if input type file is empty ...
Date Fri, 15 Oct 2010 10:38:20 GMT
Hello developers, 

i try to use the upload function. I use a form with a text Field, a 
Textare and some checkoxs and an input Type of file. If write somthing in 
these fields and choose a file to upload the behavior is good. The Upload 
will be executed. When i write only somthing to the other input elements 
(file choose is empty) I get an exception like this: 

Processing of multipart/form-data request failed. Stream ended 
unexpectedly 

This happens only if no file is choosen. Only the values of the other 
fields will be submitted.  This Part of code throw the exception. 

items = upload.parseRequest(request); 

Perhaps i make somthing wrong ... 

Perhaps it is a bug .... 

I don't now .... 



Best regards 

Michael Laube 

 
 
                                

Source of the form: 


<form  action="/xxx/CentralControl" method="post" class="admin" enctype=
"multipart/form-data"> 
 
                <fieldset class="admin"> 
                        <legend>News</legend> 
                        <label class="admin">&Uuml;berschrift:</label> 
                        <input type="text" name="ueberschrift" value="
${hN.ueberschrift}" size="68"/><br/> 
                        <label class="admin">Inhalt</label> 
                        <textarea class="admin" name="neuigkeit" rows="30" 
cols="60">${hN.text_aktuelles}</textarea> 
 
 
 
 
                           <label class="admin">Datei hochladen:</label><
INPUT name="userfile1" type="file"/> 

    
 
 
 
 
 
                        <label class="admin">Publizieren</label> 
 
                        <%if(hN.getVeroeffentlich_status()!=null){ %> 
                        <input type="checkbox" class="admin" name=
"publizieren" value="1" checked="checked"/><br/> 
                        <%} 
                        else{ 
                        %>         
                        <input type="checkbox" class="admin" name=
"publizieren" value="1" /><br/> 
                        <%} %>         
 
 
 
                        <label class="admin">News Bw </label> 
 
                        <%if(hN.getNewsbw()!=null){ %>                 
                        <input type="checkbox" class="admin" name="newsbw" 
value="1" checked="checked"/> 
                        <%} 
                        else{ 
                        %> 
                        <input type="checkbox" class="admin" name="newsbw" 
value="1"/> 
                        <%} %> 
 
                        <label class="admin">News UAN</label> 
 
                        <%if(hN.getNewsuan()!=null){ %> 
                        <input type="checkbox" class="admin" name=
"newsuan" value="1" checked="checked"/> 
                        <%}else{ %> 
                        <input type="checkbox" class="admin" name=
"newsuan" value="1"/> 
                        <%} %> 
 
 
                        <label class="admin">Löschkennzeichen: </label> 
                        <%if(hN.getLoeschkennzeichen()!=null){ %> 
                        <input type="checkbox" class="admin" name=
"loeschkennzeichen" value="1" checked="checked"/> 
                        <%}else{ %> 
                        <input type="checkbox" class="admin" name=
"loeschkennzeichen" value="1" /> 
                        <%} %> 
 
 
                        <label class="admin">E-Mail Nachricht: </label> 
                        <input type="checkbox" class="admin" name=
"newsuansendmail" value="1"/> 
 
                        <input type="hidden" name="hiddenNewsId" value="
${hN.id}" /> 
        </fieldset> 
        <fieldset class="button"> 
                        <input type="hidden" name="servletName" value=
"saveNews"/> 
                        <input type="hidden" name="jsessionid" value="<%=
session.getId()%>"/> 
                        <input type="submit" name="sendIt" value=
"Speichern"/> 
        </fieldset> 
</form> 

Source of Servlet Logic: 

System.out.println("Multi Form Data Parameter auslesen ------->:"); 
                        PrintWriter pw = response.getWriter();   
                        String n="";String v="";   
 
 
                        FileItemFactory   factory = new 
DiskFileItemFactory(); 

                        

 
 
                        ServletFileUpload upload = new 
ServletFileUpload(factory);   
                        upload.setFileSizeMax(50000000); 
                        upload.setSizeMax(-1); 


                        List items = null;   
 
                        try {   
 
                                items = upload.parseRequest(request); 
 
 
                        } 
                        catch (FileUploadException e) {   
                                System.out.println(e.getMessage()); 
                                System.out.println("Exception:-) 
--------->>>>>>"); 
                        } 
                        if(items!=null){ 
                        System.out.println("Nach Try Upload ... 
------->>>>>>"); 
 
                        Iterator itr = items.iterator();   
 
 
                        while (itr.hasNext()) {   
                                FileItem item = (FileItem) itr.next();   
 
                                if (item.isFormField()){   
                                        n=item.getFieldName();   
                                        if(n.equalsIgnoreCase("jsessionid"
)){   
                                                v=item.getString();   
 
                                        }   
                                        else if(n.equalsIgnoreCase(
"ueberschrift")){ 
                                                v=item.getString(); 
 paramContainer.setUeberschrift(v); 
                                        } 
                                        else if(n.equalsIgnoreCase(
"neuigkeit")){ 
                                                v=item.getString();   
 paramContainer.setNeuigkeit(v); 
                                        } 
                                        else if(n.equalsIgnoreCase(
"publizieren")){ 
                                                v=item.getString();   
 paramContainer.setPublizieren(v); 
                                        } 
                                        else if(n.equalsIgnoreCase(
"newsbw")){ 
                                                v=item.getString();   
 paramContainer.setNewsbw(v); 
                                        } 
                                        else if(n.equalsIgnoreCase(
"newsuan")){ 
                                                v=item.getString();   
 paramContainer.setNewsuan(v); 
                                        } 
                                        else if(n.equalsIgnoreCase(
"loeschkennzeichen")){ 
                                                v=item.getString();   
 paramContainer.setLoeschkennzeichen(v); 
                                        } 
                                        else if(n.equalsIgnoreCase(
"newsuansendmail")){ 
                                                v=item.getString();   
 paramContainer.setNewsuansendmail(v); 
                                        } 
                                        else if(n.equalsIgnoreCase(
"hiddenNewsId")){ 
                                                v=item.getString();   
 paramContainer.setHiddenNewsId(Integer.parseInt(v)); 
                                        } 
                                        else if(n.equalsIgnoreCase(
"servletName")){ 
                                                v=item.getString();   
 paramContainer.setServletName(v); 
                                        } 
                                }   
                                else{   
                                        System.out.println(
"-----------------------------------------------"); 
                                        System.out.println("Es handelt 
sich um eine Datei ..."); 
                                        String itemName = item.getName();  

                                        try{   
                                                System.out.println("Datei 
speichern ..."); 
                                                InputStream is = 
item.getInputStream(); 

 paramContainer.setFileNews(is); 
                                        }   
                                        catch (Exception e){   
                                                System.out.println("Datei 
speichern mißlungen ..."); 
                                                System.out
.println(e.getMessage());   
                                                System.out.println(
"Exception:-) --------->>>>>>"); 
                                        }   
                                } 
                        } 


====================================================
HIL Heeresinstandsetzungslogistik GmbH
Sitz Bonn
Amtsgericht-Registergericht-Bonn - HRB 13651
Geschäftsführer: Ulrich Frieling (Sprecher), Günter Schwarz
Aufsichtsratsvorsitzender: Willi Walgenbach

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message