Upload Multiple files using getparts ()

Source: Internet
Author: User

<! DOCTYPE html>

@MultipartConfig (location = "E:/workspace") @WebServlet (name = "Uploadservlet", Urlpatterns = {"/uploadservlet"}) public class Uploadservlet extends HttpServlet {/** * Processes requests for both HTTP * <code>get</     Code> and * <code>POST</code> methods. * * @param request servlet Request * @param response servlet response * @throws servletexception if a servlet- Specific error occurs * @throws IOException if an I/O error occurs */protected void ProcessRequest (HttpServlet Request request, HttpServletResponse response) throws Servletexception, IOException {request.setcharact        Erencoding ("Utf-8"); Iterates all part objects in collection for (section part:request.getParts ()) {//handles only the upload file segment if (Part.getname ()                . StartsWith ("file")) {String fileName = GetFileName (part);            Part.write (FileName);      }}} private String GetFileName (part part) {  String Header = Part.getheader ("content-disposition");        String fileName = header.substring (Header.indexof ("filename=\") + Ten, header.lastindexof ("\" "));        Header.lastindexof ("\" ");    return fileName; }//<editor-fold defaultstate= "collapsed" desc= "httpservlet methods. Click on the + sign on the left to edit the code.     >/** * Handles the HTTP * <code>GET</code> method. * * @param request servlet Request * @param response servlet response * @throws servletexception if a servlet- Specific error occurs * @throws IOException if an I/O error occurs */@Override protected void doget (Httpser Vletrequest request, HttpServletResponse response) throws Servletexception, IOException {ProcessRequest    (Request, response);     }/** * Handles the HTTP * <code>POST</code> method. * * @param request servlet Request * @param response servlet response * @throws ServleTexception If a servlet-specific error occurs * @throws IOException if an I/O error occurs */@Override Prot ected void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, Ioexceptio    n {processrequest (request, response);     }/** * Returns A short description of the servlet. * * @return A String containing servlet description */@Override public String Getservletinfo () {RET    Urn "short description"; }//</editor-fold>}

  

 

Upload Multiple files using getparts ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.