这是继续我之前没有正确构思的问题。
我在一个jsp类中有一个iframe,它在src中调用一个struts2动作类,但不是在框架内部打开文件,而是
内部文件TempContentPage.jsp:
<s:form>
<iframe id="displayFrame" src="ContentPage.action" width="1000" height="500" FRAMEBORDER="0" value="1"> </iframe>
</s:form>
这是动作类ContentPage.java中的execute方法
public String execute()抛出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;
}
这是struts.xml映射
<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>
我想打开iframe范围内的文件,请帮帮我(我从Balusc获得了宝贵的输入)因此代码中的更改:)。
谢谢, 阿迪亚
答案 0 :(得分:1)