Pdf mapping using Struts2 in Jsp

My problem is that I cannot display pdf generated on jsp using Struts2.

I can dynamically generate PDF using Dynamic Jasper in struts2 as well

download it with

result type = "stream" The only problem I'm stuck with is pdf mapping to jsp. I can

displays it using an iframe tag, but it displays an old pdf file that is not created at runtime.

If anyone has any suggestions, help me in advance in advance

+4
source share
1 answer
Action Class public class GeneratePdf extends ActionSupport { public InputStream inputStream; File file = new File("D:\\workspace\\desktopApp\\HRIS_Updated\\WebContent\\Jasper\\hris.employee.report.AwardReport.pdf"); public String execute(){ try { inputStream = new DataInputStream( new FileInputStream(file)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return SUCCESS; } public void setInputStream(InputStream inputStream) { this.inputStream = inputStream; } public InputStream getInputStream() { return inputStream; } } 

in .xml file

 <action name="GeneratePdf" class="hris.report.action.GeneratePdf"> <result name="success" type="stream"> <param name="contentType">application/pdf</param> <param name="inputName">inputStream</param> <param name="contentDisposition">inline;filename="test.pdf"</param> <param name="bufferSize">1024</param> </result> </action> 

Hope this helps :)

+4
source

All Articles