servlets - How do you retrieve multipart POST request in Java SE 8? -
java se 8 comes servlet spec 3.0 thought easy process multipart post request, wrong.
i 0 parts, although see in chrome network debugger payload contains 2 images!
what doing wrong?
here java code processing post request:
if (request.ismultipartrequest()) { collection<part> parts = request.getparts(); log.info("number of parts: "+parts.size()); (part part : parts) { string filename = getfilename(part); log.info("filename = "+filename); } } ... private string getfilename(part part) { string contentdisp = part.getheader("content-disposition"); system.out.println("content-disposition header= "+contentdisp); string[] tokens = contentdisp.split(";"); (string token : tokens) { if (token.trim().startswith("filename")) { return token.substring(token.indexof("=") + 2, token.length()-1); } } return ""; }
it logs 0 parts.
i'm using tomcat 7 , java se 8.
i think weird have getfilename()
method in own code, expected java 8 me...
any hints on how make work appreciated!
edited removed previews answer because there better one: https://stackoverflow.com/a/2424824/1484621 think you.
for clarify, java se 8 , servlet spec 3.0 not bonded together, sevlet 3.0 can work java 7 if not earlier versions. servlet specification released containers, , here error found maybe container depended, switch container(tomcat/jetty/glassfish) , try again. luck!
Comments
Post a Comment