[prev in list] [next in list] [prev in thread] [next in thread]
List: jakarta-commons-user
Subject: Re: Commons Upload: Can not read parameters if input type file is empty ...
From: Brian Pontarelli <brian () pontarelli ! com>
Date: 2010-10-15 14:38:26
Message-ID: F0DD1F04-41D9-403F-B471-B0F04FD0181E () pontarelli ! com
[Download RAW message or body]
The code and HTML look good. I've gotten that message a number of times and what it \
generally means is that the request body isn't properly formatted. More specifically, \
when the MultipartStream is asking the underlying stream (in this case the \
ServletInputStream) for more bytes it returns -1 signifying the end of the body.
Is anything else touching the InputStream before your code does? That could cause \
issues.
Another thing I would try is to read in the request body and output to stdout. This \
will help you determine if it looks like properly formatted multipart body. You could \
also post that output to the list and we can take a look as well.
-bp
On Oct 15, 2010, at 4:38 AM, michael.laube@hilgmbh.de wrote:
> 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">Ü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
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic