public void doDelete(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { for(File f : getFiles()){ if (f.getName().equals(request.getAttribute("word"))) { try { File filetodelete = new File(path+request.getAttribute("word")); filetodelete.delete(); } catch (Exception e) { //handle it } } } }