博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Servlet3.x 实现上传文件
阅读量:6604 次
发布时间:2019-06-24

本文共 4111 字,大约阅读时间需要 13 分钟。

  hot3.png

1.web.xml必须是3.0以上版本

2.在web.xml中的spring 的DispatcherServlet配置multipart-config

spring
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:webApplicationContext.xml
1
1000000
spring
/

3.spring上下文中配置StandardServletMultipartResolver

4.Controller中实现

@RequestMapping(value = "", method = RequestMethod.POST)@ResponseBodypublic ResponseEntity
uploadFile(HttpServletRequest request) { Part part = request.getPart(inputName); InputStream in = part.getInputStream();}

5.参考

5.1
5.2
6.相关异常
6.1异常信息:

java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided	at org.apache.catalina.connector.Request.parseParts(Request.java:2680)	at org.apache.catalina.connector.Request.getParts(Request.java:2647)	at org.apache.catalina.connector.RequestFacade.getParts(RequestFacade.java:1083)	at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.parseRequest(StandardMultipartHttpServletRequest.java:92)	at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.
(StandardMultipartHttpServletRequest.java:85) at org.springframework.web.multipart.support.StandardServletMultipartResolver.resolveMultipart(StandardServletMultipartResolver.java:76) at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1091) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:930) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869) at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

6.2原因

servlet没有配置multipart-config>

1000000

转载于:https://my.oschina.net/jast90/blog/729111

你可能感兴趣的文章
httpd.conf的基本设置
查看>>
读一本跟技术无关的书籍
查看>>
RHEL/Centos7新功能
查看>>
Drupal 7 数据库 操作
查看>>
第一部分 思科九年 一(1)
查看>>
DBA日常工作职责
查看>>
Redis的持久化
查看>>
linux安装NFS服务器学习
查看>>
Planner .NET日历日程控件能给你的应用程序提供多种日历日程功能
查看>>
我的友情链接
查看>>
Linux压力测试
查看>>
JAVA中的线程机制(二)
查看>>
nginx安装与配置2(转载)
查看>>
Linux下Mongodb安装和启动配置
查看>>
2015 成长计划
查看>>
沈阳一饭店凌晨爆燃,燃气报警器时刻预防
查看>>
Redis 与 数据库处理数据的两种模式
查看>>
VUE2中axios的使用方法
查看>>
assert 断言
查看>>
CS 229 notes Supervised Learning
查看>>