java - Servlet 3.0 File Upload Handling Exceptions -
i trying use java servlet 3.0 upload files.
@webservlet("/uploadfile") @multipartconfig(filesizethreshold=1024*1024*1, // 1 mb maxfilesize=1024*1024*10, // 10 mb maxrequestsize=1024*1024*100) // 100 mb public class fileuploadservlet extends httpservlet { @override protected void dopost(httpservletrequest req, httpservletresponse res) throws servletexception, ioexception { string serveruploaddir = getserveruploaddir(req); part file; try { file = req.getpart("filename"); file.write(serveruploaddir + file.separator + file.getsubmittedfilename()); res.sendredirect("viewdirectory?msg=file uploaded."); } catch (illegalstateexception ex) { system.out.println(ex.getmessage()); } } public string getserveruploaddir(httpservletrequest req) { return req.getparameter("serveruploaddir"); } }
it works correctly, when files under maxfilesize
declared in @multipartconfig annotation. however, when on size, illegalstateexception , browser says connection reset. if try forward request different page in catch, doesn't work.
i know spring framework, can create filtermultipartresolver
, it'll allow me handle when maxuploadsize
exceeded. there way create regular java servlet filter same thing?
Comments
Post a Comment