title: The server encountered an internal error () that prevented it from fulfilling the multiple file upload request
body: <p>Can anyone please help in resolving error? Trying to upload multiple files in server folder and filename is in database but server throwing following error -</p>
  
  <blockquote>
    <p>HTTP Status 500</p>
  </blockquote>
  
  <p>type Exception report</p>
  
  <p>message</p>
  
  <blockquote>
    <p>description The server encountered an internal error () that prevented
    it from fulfilling this request.</p>
  </blockquote>
  
  <p>exception</p>
  
  <blockquote>
    <p>java.io.IOException: java.io.FileNotFoundException:
    F:\eworkspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\UploadServlet30\uploadFiles
    (Access is denied)
      net.codejava.servlet.UploadServlet.doPost(UploadServlet.java:53)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722) root
    cause</p>
    
    <p>java.io.FileNotFoundException:
    F:\eworkspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\UploadServlet30\uploadFiles
    (Access is denied)    java.io.FileOutputStream.open(Native Method)
      java.io.FileOutputStream.(Unknown Source)
      java.io.FileOutputStream.(Unknown Source)
      org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.write(DiskFileItem.java:425)
      net.codejava.servlet.UploadServlet.doPost(UploadServlet.java:53)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)</p>
  </blockquote>
  
  <h2>Controller class</h2>
  
  <pre><code>protected void doPost(HttpServletRequest request,
          HttpServletResponse response) throws ServletException, IOException {
  
  
      News news = new News();
  
      // gets absolute path of the web application
      String appPath = request.getServletContext().getRealPath("");
      // constructs path of the directory to save uploaded file
      String savePath = appPath + File.separator + UPLOAD_DIR;
  
      // creates the save directory if it does not exists
      File fileSaveDir = new File(savePath);
      if (!fileSaveDir.exists()) {
          fileSaveDir.mkdir();
      }
  
      for (Part part : request.getParts()) {
          System.out.println("partttttttttt"+part.getName());
          String fileName = extractFileName(part);
          System.out.println("fle Name-----"+fileName);
          // refines the fileName in case it is an absolute path
          fileName = new File(fileName).getName();
          System.out.println("fle Name-----"+fileName);           
          part.write(savePath + File.separator + fileName);
          news.setFileName(fileName);
      }
  
      news.setNewsTitle(request.getParameter("newsTitle"));
      news.setNewsDesc(request.getParameter("newsDesc"));
  
  
      String newsId = request.getParameter("newsId");
  
      if(newsId == null || newsId.isEmpty())
      {
          dao.addNews(news);
      }
      else
      {
          news.setNewsId(Integer.parseInt(newsId));
          dao.updateNews(news);
      }
      RequestDispatcher view = request.getRequestDispatcher(LIST_NEWS);
      request.setAttribute("newsList", dao.getAllNews());
      view.forward(request, response);
  
  }
  
  /**
   * Extracts file name from HTTP header content-disposition
   */
  private String extractFileName(Part part) {
      String contentDisp = part.getHeader("content-disposition");
      String[] items = contentDisp.split(";");
      for (String s : items) {
          if (s.trim().startsWith("filename")) {
              return s.substring(s.indexOf("=") + 2, s.length()-1);
          }
      }
      return "";
  }
  </code></pre>
  
  <p>and the dao</p>
  
  <pre><code>public void addNews(News news) {
      String insertQuery = "INSERT INTO NEWSMASTER(NEWSID, NEWSTITLE, NEWSDESC,FILENAME) VALUES (?,?,?,?)";
      try {
          pStmt = dbConnection.prepareStatement(insertQuery);
          pStmt.setInt(1, news.getNewsId());
          pStmt.setString(2, news.getNewsTitle());
          pStmt.setString(3, news.getNewsDesc());
          pStmt.setString(4, news.getFileName());
          pStmt.executeUpdate();
      } catch (SQLException e) {
          System.err.println(e.getMessage());
      }
  }
  </code></pre>
  
  <h2>model class</h2>
  
  <pre><code>public String getFileName() {
      return fileName;
  }
  public void setFileName(String fileName) {
      this.fileName = fileName;
  }
  </code></pre>