Your second method is fine just make sure your web.xml has the same url mapping for your servlet "/PDFDisplayServlet".