- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试上传 Excel 文件并在控制台中打印每个单元格的内容。这是我的代码..
JSP:
<c:url value="/my-account/readExcel" var="readExcel" />
<form:form action="${readExcel}" method="post" commandName="excelFileUploadForm" enctype="multipart/form-data">
<form:input id="fineName" path="fileName" type="file" />
<input type="submit" value="Uplaod" />
</form:form>
Excel文件上传表单:
public class ExcelFileUploadForm
{
private MultipartFile fileName;
public MultipartFile getFileName()
{
return fileName;
}
public void setFileName(final MultipartFile fileName)
{
this.fileName = fileName;
}
}
Controller :
@RequestMapping(value = "/readExcel", method = RequestMethod.POST)
@RequireHardLogIn
public String readExcel(final HttpServletRequest request, final HttpServletResponse response) throws CMSItemNotFoundException,
IOException
{
final MultipartHttpServletRequest mpr = (MultipartHttpServletRequest) request;
final CommonsMultipartFile file = (CommonsMultipartFile) mpr.getFile("fileName");
read(file);
return "redirect:/my-account";
}
public void read(final CommonsMultipartFile inputFile) throws IOException
{
Workbook w;
try
{
w = Workbook.getWorkbook(inputFile.getInputStream());
// Get the first sheet
final Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
for (int j = 0; j < sheet.getColumns(); j++)
{
for (int i = 0; i < sheet.getRows(); i++)
{
final Cell cell = sheet.getCell(j, i);
final CellType type = cell.getType();
if (type == CellType.LABEL)
{
System.out.println("I got a label " + cell.getContents());
}
if (type == CellType.NUMBER)
{
System.out.println("I got a number " + cell.getContents());
}
}
}
}
catch (final BiffException e)
{
e.printStackTrace();
}
}
当我通过浏览按钮上传文件并单击上传时。它给出了类型转换错误
HTTP Status 500 - Request processing failed; nested exception is java.lang.ClassCastException: org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
我不知道我哪里做错了。请帮忙。
最佳答案
请在您的 spring 配置(应用程序配置)中添加 Multipart Resolver,如下所示:
<bean id="multiPartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
关于java - HttpServletRequest 无法转换为 MultipartHttpServletRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23624688/
我有一个 html 表单要提交,如下所示: Other inputs here... 在服务器端,我想获取所有输入(文件和文本输入)...并且表单是动态创建的,所以我事先不知道 I
创建 MultipartHttpServletRequest 时出现异常。我已经创建了 HttpServletRequest 但是当使用 MultipartHttpServletRequest 进行转
我想使用此策略从网页上传文件。即 Ajax file upload tutorial .一切正常,但问题出在服务器端,我想在服务器端打开此文件并读取其内容。我对在提交表单时调用的方法使用以下签名。即
我正在尝试上传 Excel 文件并在控制台中打印每个单元格的内容。这是我的代码.. JSP:
尝试测试我们用于多个文件上传的 spring Controller 。这是 Controller : @RequestMapping("/vocabularys") @Controller publi
我已将访问决策管理器配置为在请求被 servlet 处理之前检查请求,关键行是:- HttpServletRequest request = (HttpServletRequest) RequestC
您好,我必须进行 Resttemplate 调用才能对以下函数进行调用,其中参数是 MultiPartHttpServletRequest 请求、HttpServletRequest requestF
我正在尝试通过 Angular 1.5 将文件上传到 Spring REST 端点。 我没有收到任何错误,因为 multiPartRequest.getFileNames(); 返回 null。但是我
这个问题已经有答案了: Using Spring MVC Test to unit test multipart POST request (5 个回答) 已关闭 5 年前。 我正在尝试为包含以下方法
我正在尝试上传 .jpg 文件,但收到此消息: org.springframework.web.util.NestedServletException: Request processing fail
我正在尝试使用下面的方法上传文件。但我收到 java.lang.IllegalStateException: Current request is not of type [org.springfra
public HttpResponseMessage run( @HttpTrigger(name = "req", methods = {HttpMethod.GET, Ht
我有一个具有此类配置的网络应用程序。请查看 multipartResolver bean。 @Configuration @EnableWebMvc @ComponentScan(basePackag
我是一名优秀的程序员,十分优秀!