- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Apache Commons Streaming API 从 Excel 电子表格中获取信息。我不断收到以下错误:
SEVERE: org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:908)
at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
at org.apache.commons.fileupload.servlet.ServletFileUpload.getItemIterator(ServletFileUpload.java:148)
at eBooks.controller.ReportServlet.processRequest(ReportServlet.java:54)
at eBooks.controller.ReportServlet.doPost(ReportServlet.java:178)
at eBooks.controller.ReportServlet.doGet(ReportServlet.java:170)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
INFO: Reports
INFO: Form field upload_report_btnwith valueUpload Report detected
SEVERE: org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:908)
at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
at org.apache.commons.fileupload.servlet.ServletFileUpload.getItemIterator(ServletFileUpload.java:148)
at eBooks.controller.ReportServlet.processRequest(ReportServlet.java:54)
at eBooks.controller.ReportServlet.doPost(ReportServlet.java:178)
at eBooks.controller.ReportServlet.doGet(ReportServlet.java:170)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
SEVERE: org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:908)
at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
at org.apache.commons.fileupload.servlet.ServletFileUpload.getItemIterator(ServletFileUpload.java:148)
at eBooks.controller.ReportServlet.processRequest(ReportServlet.java:54)
at eBooks.controller.ReportServlet.doPost(ReportServlet.java:178)
at eBooks.controller.ReportServlet.doGet(ReportServlet.java:170)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
这是处理信息的ReportServlet代码:
package eBooks.controller;
/**
* @author L10
*/
import eBooks.business.Account;
import eBooks.business.Report;
import eBooks.business.User;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSession;
import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.util.Streams;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class ReportServlet extends HttpServlet
{
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try
{
// Check that we have a file upload request
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
//Create a new file upload Handler
ServletFileUpload upload = new ServletFileUpload();
//Parse the request
FileItemIterator iter = upload.getItemIterator(request);
while(iter.hasNext())
{
FileItemStream item = iter.next();
String name = item.getFieldName();
InputStream stream = item.openStream();
if(item.isFormField())
{
System.out.println("Form field " + name + "with value" + Streams.asString(stream) + " detected" );
}
else
{
POIFSFileSystem fs = new POIFSFileSystem(stream);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
System.out.println(wb.getSheetName(0));
// session
HttpSession session = request.getSession();
//Define define values obatained from the document
Report report = new Report();
User user = new User();
Account account = new Account();
int reportType = report.getReportType();
String emailAddress = user.getEmailAddress();
String account_id = account.getAccount_id();
String accountName = account.getAccountName();
String userRole = user.getUserRole();
String reportName = report.getReportName(); // is the spreadsheet Name
String reportDate = report.getReportDate(); // is the period on the report
double totalUS = report.getMonthTotalUS();
double totalEUR = report.getMonthTotalEUR();
double grandTotal = report.getMonthGrandTotal();
double averagePrice = report.getAverageSalePrice();
int totalUnitsSold = report.getTotalUnitsSold();
double monthlyAverageUnitsSold = report.getMonthlyAverageUnitsSold();
double dailyAverageUnitsSold = report.getDailyAverageUnitsSold();
int totalUnitsRefunded = report.getTotalUnitsRefunded();
double monthlyAverageUnitsRefunded = report.getMonthlyAverageUnitsRefunded();
double dailyAverageUnitsRefuded = report.getDailyAverageUnitsRefuded();
double monthlyAverageRoyalties = report.getMonthlyAverageRoyalties();
// set values for the user, account & report objects
report.setReportType(reportType);
user.setEmailAddress(emailAddress);
account.setAccount_id(account_id);
account.setAccountName(accountName);
user.setUserRole(userRole);
report.setReportName(reportName); // is the spreadsheet Name
report.setReportDate(reportDate); // is the period on the report
report.setMonthTotalUS(totalUS);
report.setMonthTotalEUR(totalEUR);
report.setMonthGrandTotal(grandTotal);
report.setAverageSalePrice(averagePrice);
report.setTotalUnitsSold(totalUnitsSold);
report.setMonthlyAverageUnitsSold(monthlyAverageUnitsSold);
report.setDailyAverageUnitsSold(dailyAverageUnitsSold);
report.setTotalUnitsRefunded(totalUnitsRefunded);
report.setMonthlyAverageUnitsRefunded(monthlyAverageUnitsRefunded);
report.setDailyAverageUnitsRefuded(dailyAverageUnitsRefuded);
report.setMonthlyAverageRoyalties(monthlyAverageRoyalties);
// TODO: Add information to the database
// set Session for the user, account & report
session.setAttribute("User", user);
session.setAttribute("Account", account);
session.setAttribute("Report", report);
Cookie emailCookie = new Cookie("emailCookie", emailAddress);
emailCookie.setMaxAge(60*60*24*365*2);
emailCookie.setPath("/");
response.addCookie(emailCookie);
String url = "/WEB-INF/view/Dashboard.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
}
}catch (FileUploadException ex) {
Logger.getLogger(ReportServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
}
这就是我的表单的外观:
<form action="ReportServlet" method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
<br />
<input type="submit" value="Upload Report" name="upload_report_btn" />
</form>
我正在使用玻璃鱼。有什么想法为什么我不断收到此消息吗?
最佳答案
在您的循环中,您似乎假设到达的第一个也是唯一的多部分对象将是电子表格文件。表格本身也会出现。线索就是消息
Unable to read entire header; 13 bytes read; expected 512 bytes
请注意,表单的上传值为Upload Report
,长度恰好为13 个字节。
如果您使用基于浏览器的调试工具(例如 Firebug 或 Fiddler),您可以很容易地看到这一点。您的工具集中应该包含这些工具之一。
关于java - FileUpload (Apache Commons) 和 Java POI IOException : Unable to read entire header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11074683/
我们有一个连接到某些网络服务的 Windows 窗体应用程序。它列出了系统中的文档,当用户双击一个文件时,我们将文件下载到本地计算机并打开文档供他们编辑。一旦用户关闭文档,我们就会将其上传回系统。 对
public class SampleCloseable implements AutoCloseable { private String name; public SampleCl
我正在尝试使用 JAVA 运行一个简单的 sqoop 导入程序。 我的程序: String driver="com.vertica.Driver"; Configuration con
我需要从 Java 执行一个外部程序(使用 libreoffice 将 fodt 文件转换为 pdf,就这样发生了)我知道该程序所需的精确命令行: /usr/bin/libreoffice --hea
AFAIK,标准try-with-resources 形式 try(InputStream is= new ...){ ... some reading from is } catch (..
我观察到这两种说法都是有效的。与第二个语句相比,第一个语句中记录的额外内容是什么? 最佳答案 第一个还记录原始异常(和堆栈跟踪),第二个仅记录消息。 因此,第一个语句中记录的“额外内容”是原始异常。这
我想执行重命名和删除功能,环境是LINUX。这是我正在使用的代码, String[] command_ary = { "/usr/bin/sh", "-c", command }; Runtime r
在使用 selenium webdriver 实现 Web 应用程序的自动化时,我遇到了一种情况,我需要上传文件并进一步继续。 我们为此使用 Java 和 Tcl 脚本语言。 下面是我的 TCL 代码
我正在尝试使用 ANT 将文件从一个目录复制到 Linux 上的另一个目录。 首先我使用了复制任务,它工作正常但文件模式没有保留。然后我改为使用 ,这就是我卡住的地方。 我的目标是这样的:
当我输入命令时: ./sqoop-import --connect jdbc:mysql://localhost/sqoop2 -table sqeep2 -m 1 -hive-import 当执行这
我正在使用 Sun 的 keytool 创建一个 Bouncy caSTLe keystore 并将证书导入其中。 keytool 确实会生成一个 Bouncy caSTLe 格式的 keystore
我正在执行下面的程序,它通过 java 调用 shell,我得到了异常请帮助我。 程序: import java.io.*; import java.util.*; public class Proc
我在我的一个项目中遇到了这个错误。 FAILURE: Build failed with an exception. What went wrong: Execution failed for tas
什么情况下read end可以死对偶PipedOutputStream和 PipedInputStream ?我没有关闭任何管道。 最佳答案 我遇到了java.io.IOException: Read
我有一段从文件中读取数据的代码。我想在此代码中强制 IOException 用于测试目的(我想检查代码在这种情况下是否抛出正确的自定义异常)。 例如,有什么方法可以创建一个防止被读取的文件?也许处理一
我为MapReduce文本排序编写了这样的代码: public static class SortMapper extends Mapper { private Text citizenshi
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我要createNewFile有一条路径,但我得到了一个 IOException。问题是,详细的消息无法解释,我只能看到一堆问号。 我最初使用的是西类牙语的 Windows 10,但安装了中文语言包。
我认为这是基本的东西,但我不知道该怎么做。为什么我得到 IOException never throw in body of相应的 try 语句 public static void main(Str
我正在从 Java 项目中的类路径读取文件。 示例代码: public static Properties loadPropertyFile(String fileName) {
我是一名优秀的程序员,十分优秀!