Display a Pdf using Struts2 in a Jsp
struts2
Solution
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 the .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 it Helps :)
Problem
My problem is i am not able to display the pdf generated on jsp using Struts2. I am able to generate the pdf dynamically using Dynamic Jasper in struts2 and also able to download it using the result type="stream" the only problem i am stuck at is displaying the pdf in jsp. i able to display it using iframe tag but it display the old pdf not the one i generate at runtime. if anyone has any suggestions do help me out thanks in advance