I useache Commons fileUpload to receive uploaded file in a Servlet, as specified at
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
InputStream stream = item.openStream();
if (!item.isFormField()) {
System.out.println("Got an uploaded file: " + item.getFieldName()
+ ", name = " + item.getName() + " type = " + item.getContentType());
}
我不敢肯定,项目.getContentType()还将包含可能不同于请求编码(例如ISO-8859-1)的案文档案编码,或者如果它始终只包含档案类型的话。 在我的测试中,我只收到“文字/解释”,但我期望收到客户发出的“文字/解释;Encoding=ISO-8859-1”。
我的理解是,该项目应当包括编码(如果是从客户发送的)?