java - ServletFileUpload - ItemIterator 的顺序

标签 java html servlets file-upload

我正在使用公共(public) FileUpload 作为自定义 uploader 实现的一部分。特别是,我正在使用 ServletFileUpload 和 Streaming API ( http://commons.apache.org/fileupload/streaming.html )。 ServletFileUpload 中 getItemIterator() 方法的 API 表明它保证返回 FileItemStreams 的迭代器,按照“它们被传输的顺序”。也许这是一个愚蠢的问题,但是在提交HTML表单时,这个顺序是否保证是HTML表单输入存在于相应HTML页面的顺序?到目前为止,情况似乎是这样,但我需要确保这是有保证的行为。

示例:

<form method="post" name="test" action="/upload">
    <input type="hidden" name="param1" value="1" />
    <input type="hidden" name="param2" value="2" />
    <input type="hidden" name="param3" value="3" />
    <input type="file" name="test_file" />
</form>


// Example JAVA ...
// Is the iterator guaranteed to return streams in the order: param1, param2, param3, test_file?
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(request);

最佳答案

是的,这又在 W3C HTML Forms Spec 中指定- Chapter 17.13.4 Form content types .这是相关性的摘录(请参阅最后一段中的重点):

17.13.4 Form content types

...

application/x-www-form-urlencoded

This is the default content type. Forms submitted with this content type must be encoded as follows:

Control names and values are escaped. Space characters are replaced by '+', and then reserved characters are escaped as described in [RFC1738], section 2.2: Non-alphanumeric characters are replaced by '%HH', a percent sign and two hexadecimal digits representing the ASCII code of the character. Line breaks are represented as "CR LF" pairs (i.e., '%0D%0A').

The control names/values are listed in the order they appear in the document. The name is separated from the value by '=' and name/value pairs are separated from each other by '&'.

关于java - ServletFileUpload - ItemIterator 的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6591547/

相关文章:

java - 将值从表插入到另一个表时发生 Servlet 异常( java.lang.StackOverflowError )

java - 嵌入 Tomcat-7 以仅在 https 中运行

java - 如何将一个类的 main 方法中定义的变量转移到另一个类的 main 方法中?

javascript - CSS 调整图像大小以适应 div 并响应

html - 如何在 <ul> 标签中选择第二个和第三个元素(li)(使用 CSS)?

java - Spring MVC 应用程序中的性能

java - Eclipse 在循环中执行 java 应用程序

java - 简单解析例程的问题

javascript - 如何使用 Bootstrap 或 CSS 将容器 div 覆盖在另一个容器上

java - Servlet 只读取 Excel 文件的前两行