I have found the solution. you have to make a servlet that is responsible for downloading the file. To do this you have to remove the servlet.xml path that you had added before.
Up:
String subirArchivo(int codigo, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
Part filePart = request.getPart("archivo"); // Obtiene el archivo
String fileName = Paths.get(filePart.getSubmittedFileName()).getFileName().toString(); // MSIE fix.
if(!fileName.isEmpty()){
String path="/archivos/";
File uploads = new File(path); //Carpeta donde se guardan los archivos
uploads.mkdirs(); //Crea los directorios necesarios
File file = File.createTempFile("cod"+codigo+"-", "-"+fileName, uploads); //Evita que hayan dos archivos con el mismo nombre
try (InputStream input = filePart.getInputStream()){
Files.copy(input, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
return file.getPath();
}
return null;
}
Post link:
if(adjunto!=null){
String filename=adjunto.substring(10); //La longitud de /archivos/
String borrar="<a href=borrarServlet?codigo="+codigo+"&comentario="+idComentario+"&file="+filename+"><img width=\"16\" src=images/borrar.png></img></a>";
comentarios+="<tr><td>"+fecha+"</td>"+"<td>"+texto+"<br><a class=\"adj\" href=."+adjunto+">Descargar archivo</a></td><td>"+borrar+"</td></tr>";
}
Download:
String filename = URLDecoder.decode(request.getPathInfo().substring(1), "UTF-8");
File file = new File("/archivos", filename);
response.setHeader("Content-Type", getServletContext().getMimeType(filename));
response.setHeader("Content-Length", String.valueOf(file.length()));
response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");
Files.copy(file.toPath(), response.getOutputStream());