我想使用java代码(servlet)
打开一个文件在我的jsp文件中,我有一个按钮,它将调用java代码以便在我的Web应用程序中打开文件,
我在jsp页面中有这个代码
<input type="button" onclick="javascript:action_consultDoc()"
value="<util:message key="test.action.consultDoc.title"/>" />
<script type="text/javascript">
function action_consultDoc() {
documentService.consultDoc(Ext.getCmp('userId').getValue(), {
callback : function(responseEntity) {
}
});
</script>
在我的代码java中我有
public class documentService{
public void consultDoc(String userid) {
.//here is the code of c
byte[] file= c.execute(connector, doc);
// I have a file in this format : byte[]
//here I should call a methode get of servlet
}
}
我尝试使用此代码而没有成功
public class documentService{
public void consultDoc(String userid) {
.//here is the code of c
byte[] file= c.execute(connector, doc);
// I have a file in this format : byte[]
//here I should call a methode get of servlet
HttpServletResponse response;
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setContentType("application/pdf");
InputStream in = new FileInputStream();
OutputStream out = response.getOutputStream();
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
}
}
答案 0 :(得分:0)
您尚未刷新或关闭输出流,即out.flush()