commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Garrett Smith" <dhtmlkitc...@gmail.com>
Subject Re: "Stream ended unexpectedly" - simple testcase
Date Tue, 15 Jul 2008 17:13:31 GMT
On Tue, Jul 15, 2008 at 9:42 AM, Mark Thomas <markt@apache.org> wrote:
> Garrett Smith wrote:
>>
>> Can't get my multipart/form-data processed. Error: "Stream ended
>> unexpectedly".
>
> Tomcat version?
>

Apache Tomcat Version 6.0.10

The post request works fine via "normal" submit, just not with XHR.

Try submitting the form:
1) normal submit - by pressing "enter" when the text input has focus.
2) XHR submit - by clicking the "send" button

Results:
1) success! (view items.toString())
2) Error in Firebug
2 files: form2.html, process.jsp

form2.html
========================================================
<!DOCTYPE HTML>
<html lang="en">
<head>
  <title>Form Serialize</title>
</head>
<body>
<form method="post"
  enctype="multipart/form-data"
  id='form' action="process.jsp">
  <input type="text" name="name" value="a"/>
  <button type="button"
    onclick="sendXHR(event);return false;">Send</button>
</form>

<pre id="result"></pre>

<script>
function sendXHR(e) {
  var req = new XMLHttpRequest();
  req.oreadystatechange = showData;
  req.open("post", "process.jsp", true);
  req.setRequestHeader('Content-Type',
    "multipart/form-data; boundary=DATA1215979532633");
  req.send('--DATA1215979532633\n'
    +'Content-Disposition: form-data; name="name";'
    +'\n\na'
    +'--DATA1215979532633--');
}


function showData() {
  var data = this.responseText;
  document.getElementById('result').innerHTML = data;
}
</script>
</body>
</html>
========================================================

process.jsp
========================================================
<%@ page import="org.apache.commons.io.*,
org.apache.commons.fileupload.*, java.io.*, java.util.*,
org.apache.commons.fileupload.disk.DiskFileItemFactory,
org.apache.commons.fileupload.servlet.*" %>
<%
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();

// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);

List<FileItem> items = upload.parseRequest(request);
response.setContentType("text/plain");
out.write(items.toString());
%>
========================================================

Garrett

> Mark
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message