1

我有一个包含h:dataTable. 数据表有一列h:commandLink组件,它们打开一个新的弹出窗口。这些 commandLink 组件actionListener在页面的支持 bean 中有一个方法。该代码确定单击了哪个 commandLink 组件,获取其参数并重定向到 servlet。servlet 将文件写入弹出窗口并显示“另存为/打开”对话框,以便用户下载写入的文件。这一切都很好。

但是,关闭弹出窗口后,如果我单击页面上的 JSF 按钮,我会再次获得“另存为/打开”对话框。如何防止此对话框再次出现?Page1.jsp我注意到如果在单击 JSF 按钮之前刷新,则不会发生这种情况。

这是代码:

Page1.jsp

<noscript>
<!-- Page1.jsp -->
    <webuijsf:button actionExpression="#{Page1.btnSubmit_action}" id="btnSubmit" text="Apply"/>

<h:column id="column9">
  <h:commandLink  value=" Open " target="popupWindow" actionListener="#{Page1.openPopupClicked}" >
<f:param id="tmpFileId" name="id" value="#{currentRow['J_LINK']}" />
</h:commandLink>
<h:outputLink target="_blank" value="#{currentRow['J_LINK']}"/>
<f:facet name="header">
<h:outputText id="outputText18" value="More "/>
</f:facet>
</h:column>
</noscript>

Page1后备豆

public void openPopupClicked(ActionEvent event){
      UIParameter tmpFileName = (UIParameter)event.getComponent().findComponent("tmpFileId");
      if(tmpFileName==null)
        return;
      String fName = (String)tmpFileName.getValue();
      if(fName==null)
        return;
      final String viewId = "/FileDisplayerServlet";
      HttpSession hs = this.getHttpSession();
      hs.setAttribute("tmpToShow", fName);
      this.redirectToServlet(viewId);     
   }

processRequest 方法调用的 Servlet 代码:

private void printFileToScreen(HttpServletRequest request,String tmpFileToShow, HttpServletResponse response)
      throws IOException{
      ServletOutputStream sos = null;
      FileInputStream in = null;
       try{
          response.reset();
          response.setContentType(getContentType(tmpFileToShow));

          if(currFileExt==null)
            return;
          String fileName = "document.".concat(currFileExt);
          sos = response.getOutputStream();
          response.setHeader("Content-disposition", "attachment; fileName="+fileName);
          File src = new File(tmpFileToShow);
          in = new FileInputStream(src);
          byte[] buf = new byte[1024];
          int len =0;

          response.setHeader("Cache-Control", "private");
          while((len = in.read(buf, 0, buf.length)) > 0){
            sos.write(buf, 0, len);
          }
        }catch(IOException ie){
          System.out.println("printFileToScr: "+ie.toString());
        }finally{
          if(sos!=null)
            {sos.flush(); sos.close();}
          if(in!=null)
          {in.close();}


        }
  }
4

0 回答 0