2 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個(gè)贊
實(shí)際上,我沒(méi)有找到為什么 @MultipartConfig 注釋對(duì)我不起作用,但我在 i-net 上發(fā)現(xiàn)了一種工作正常的解決方法:
private static final MultipartConfigElement MULTI_PART_CONFIG = new MultipartConfigElement("c:/temp");
...
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String contentType = request.getContentType();
if(contentType != null && contentType.startsWith("multipart/")){
request.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, MULTI_PART_CONFIG);
for(Part part: request.getParts()) { ... } ;
} else {
...
}
}
我認(rèn)為此解決方案可能對(duì)遇到此類問(wèn)題的開(kāi)發(fā)人員有用

TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個(gè)贊
當(dāng)您將 servlet 映射到路徑時(shí),為什么不配置它?
handler.addServlet(UploadServlet.class, "/upload/*")
.getRegistration().setMultipartConfig(
new MultipartConfigElement("./tmp")
);
到達(dá)此 servlet 的每個(gè)請(qǐng)求都將使用該屬性進(jìn)行豐富
添加回答
舉報(bào)