Hi all,
This is in continuation with my previous question which was not framed properly.
I have an iframe in a jsp class which is calling a struts2 action class in its src, but instead of opening inside the frame the file is getting downloaded,
Inside file TempContentPage.jsp:
<s:form>
<iframe id="displayFrame" src="ContentPage.action" width="1000" height="500" FRAMEBORDER="0" value="1"> </iframe>
</s:form>
Here is the execute method in the action class ContentPage.java
public String execute() throws IOException {
Session session = SessionUtil.getSession();
session.beginTransaction();
ServletOutputStream out = res.getOutputStream();
ContentBase cb = new ContentBase();
String quer = "from ContentBase cb where cb.parentType=? AND cb.parentId=? ";
Query query = session.createQuery(quer);
query.setParameter(0, "FILE");
query.setParameter(1, "1");
list = (ArrayList) query.list();
if (null != list && !((java.util.ArrayList) list).isEmpty()) {
cb = (ContentBase) ((java.util.ArrayList) list).get(0);
}
docContent = cb.getFile();
res.reset();
res.setContentType("application/msword");
res.setHeader("Content-disposition", "inline; filename=\"scovr.doc\"");
try{
InputStream in = docContent.getBinaryStream();
//InputStream iStream = new ByteArrayInputStream (docContent.getBytes(0, (int) docContent.length()));
int length = (int) docContent.length();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
while ((length = in.read(buffer)) != -1) {
out.write(buffer, 0, length);
}
player.setIsRead(true);
in.close();
}catch(Exception e){
e.printStackTrace();
}
out.flush();
return SUCCESS;
}
And here is the struts.xml mapping
<action name="ContentPage" class="com.zoran.action.ContentPage">
<result name="success" type="stream">
<param name="contentType">application/msword</param>
<param name="inputName">in</param>
<param name="bufferSize">1024</param>
<param name="contentDisposition">inline</param>
</result>
<result name="error" >/pages/ContentPage.jsp</result>
<result name="input" >/pages/ContentPage.jsp</result>
</action>
I want to open the file inside the iframe scope, Please help me out ( I got valuable inputs from Balusc ) hence changes in this code :).
Thanks, Aditya