Olá, por favor, podem me ajudar entender esse erro?
Quando eu clico no link da da capa do livro em lista.xhtml ocorre o seguinte erro:
HTTP Status 500 – Internal Server Error
Type Exception Report
Message \imagens\livrosImg\logo.png
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
java.nio.file.NoSuchFileException: \imagens\livrosImg\logo.png
sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:53)
sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:38)
sun.nio.fs.WindowsFileSystemProvider.readAttributes(WindowsFileSystemProvider.java:193)
java.nio.file.Files.readAttributes(Files.java:1737)
java.nio.file.Files.size(Files.java:2332)
br.com.caelum.loja.servlets.FileServlet.service(FileServlet.java:32)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.
Abaixo segue a linha 32 do FileServlet.java
package br.com.caelum.loja.servlets;
import java.io.IOException;
import java.net.FileNameMap;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import br.com.caelum.loja.infra.FileSaver;
@WebServlet("/file/*")
public class FileServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String path = req.getRequestURI().split("/file")[1];
Path source = Paths.get(FileSaver.SERVER_PATH + "/" + path);
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentType = fileNameMap.getContentTypeFor("file:"+source);
res.reset();
res.setContentType(contentType);
//linha32
res.setHeader("Content-Length", String.valueOf(Files.size(source)));
res.setHeader("Content-Disposition",
"filename=\""+source.getFileName().toString() + "\"");
FileSaver.transfer(source, res.getOutputStream());
}
}
Obrigado!! Huender