Reputation: 21
I am migrating Java web application from Tomcat 6 to Tomcat 8. In the application ,on a button click, pdf gets created first in 'Workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Project' folder if it does not exists and then opened in a new window.
This functionality works fine Tomcat 6 and 7 . But in Tomcat 8 ,pdf gets created but its not opening on first click(getting 404 error) . On second or third click it's getting displayed.
Below code is used to get the path of the pdf location:
String path = request.getSession().getServletContext().getRealPath("//MyPdf.pdf");
Hard coding of pdf path is working fine in Tomcat 8 as well . I am not able to understand what is the issue , suggest some alternative for the above code.
Upvotes: 0
Views: 970
Reputation: 8495
I can see 2 slashes before your file name.
String path = request.getSession().getServletContext().getRealPath("//MyPdf.pdf");
Below code should work.
String path = request.getSession().getServletContext().getRealPath("/MyPdf.pdf");
Upvotes: 0