[英]open file in jsp using servlet
我想使用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();
}
}
您尚未刷新或关闭输出流,即out.flush()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.