0

我想使用 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();

    }

}
4

1 回答 1

0

你还没有刷新或关闭你的输出流,即out.flush()

于 2013-05-23T12:23:33.130 回答