- 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/
我是 Android 编程新手。我想给cardview添加涟漪效果。实际上我找到了解决方案,但是,在触摸cardview元素后,效果似乎并没有覆盖整个cardview。我的意思是效果突然消失并且没有到
我能否通过我自己的应用程序监听放置在 LogCat 中的消息? 例如像... // Somewhere in my application (on a background service): Log
从我们办公室到 GitHub.com 的连接通常很慢,而且文件通常很大。 有没有一种简单的方法可以只使用一台机器与 GitHub 同步,而让其他机器通过 LAN pull 和推送到那台机器? 最佳答案
如何在 flutter 中使整行可点击?我将以下代码包装在“GestureDetector”中。该行中的单个项目可点击,但小部件周围的空白区域不可点击。 if ((auth.isLoggedIn))
不知何故,Visual Studio 搜索已停止为我工作。每当我搜索“整个解决方案”中的某些文本时,我都会得到以下结果: Find all "[Whatever I was searching for
我有一个 DAO 记录集,可以很好地创建,我可以将记录从该集传输到表中,这是逐行完成的并且运行良好,但我要一次传输大量数据,因此这可能需要花费一些时间一行一行的时间很长。 有没有一种方法可以一次性传输
我知道如何从 Azure 表中获取一些表实体,如下所示: CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudCon
我在 MainWindow.cpp 中实例化了一个 widgetClass。我想将“this”传递给这个小部件,不仅仅是(QWidget* parent),还有(MainWindow* parent)
使用最高级的 Flatspec 和 TimeLimits 特性,我可以为一行代码设置超时,如下所示: import org.scalatest.time.SpanSugar._ import org.
当使用“ipython”或“code.interact(local=locals())”时,我希望有一种方法可以保存整个程序地址空间到 pickle 文件中,以及类似的加载此类文件然后在该上下文中开始
我如何“隐藏”类的某些部分,以便使用该库的人不必包含我的类中使用的所有类型的 header 。即采用下面的 MainWindow 类,我可以拥有它吗,所以当在静态/动态库中编译时,使用该库的人不必包含
我使用以下行来获取出现特定字符串的行号: nLine=$(awk '/text/{ print NR; exit }' $1) echo "line = $nline" 返回: line = 78 现
我有一个很长的字符串S,包含几个格式如下的子字符串: [&FULL="583 - node#597 ,REALNAME="node#638"] 即: 以 [&FULL=" 开头 以 REALNAME
即使我从所有 config*.yml 文件中删除 web_profiler ...我越来越 RuntimeException: You need to enable either the SQLite
我在类方法中有一个带有文档字符串的 Python 模块,在模块文档字符串中有一个真实示例。区别在于方法文档字符串经过精心设计,可以完全重复测试,而真实世界的示例只是 Linux shell 历史记录的
我的站点使用 Wordpress 作为 CMS,它已经安装在一个子文件夹中,但我将其设置为显示在根域中。基本上,example.com 显示 example.com/wordpress 的内容。 旧的
我正在尝试为现有代码编写单元测试,这些代码编写得不好,但我发现很难进行单元测试。 def pay(self): fraud = NewFraudCheck() result, tran
我正在查询对象列表,然后将它们与子查询相关联。 我想返回子查询的结果,以及根实体。但是 我不知道如何实际返回根实体,我只能返回它的单个属性。 具体来说,这有效: this.Session.QueryO
我到处都是,似乎具有静态背景问题的 UITableView 有详细记录,但没有人有直接的解决方案?我完全用代码构建我的 TableViews,如下所示: UIViewController *t
直接取自 SQLite 的站点“该值是一个有符号整数,根据值的大小存储在 1、2、3、4、6 或 8 个字节中。” 这是否意味着如果您有 1 个需要 8 个字节的值,则该列中的所有值都将被视为 8 个
我是一名优秀的程序员,十分优秀!