我正在尝试构建一个可以在客户端上下载多个文件(而不是 zip 文件)的 Web 应用程序。我正在使用 jsf、jquery 和 servlet。该代码在 Mozilla 中运行良好,但在 IE8 中无法运行。
更具体地说:我希望客户端从浏览器接收 4 个不同的保存/打开提示。所以...我做了一个这样的简单示例:用户按下操作按钮>>将创建 4 个不同的 iframe,其 src 属性等于 servlet 路径>>servlet 生成带有 pdf 文件的响应>>客户端接收多个保存/打开提示
这在 Mozilla 中运行良好,但在 IE8 中,如果您按足够快的 ESC 键,您将获得 3 个保存/打开提示 :) 这还不够……我检查了是否所有 4 个请求和所有 4 个响应都已做出并且他们都在那里......我看不出提示的问题在哪里......
有什么方法可以让 jquery 等到 promt 关闭以制作下一个 iframe(请求)?我认为这即使在 IE 中也应该有效 :)
在此示例中,有 4 个使用 JasperReports 创建的 pdf。
小服务程序:
public class TestServlet extends HttpServlet {
private static final long serialVersionUID = 509291005008276860L;
private Logger logger LoggerFactory.getLogger( TestServlet.class );
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException
{
try {
Map<String, Object> params = new HashMap<String, Object>();
params.put( "JUDET", "Alba" );
params.put( "NUME", "Caliman" );
params.put( "PRENUME", "Victor" );
params.put( "DATA_NASTERE", "01/03/1987" );
params.put( "LOCALITATE", "Alba Iulia" );
params.put( "STR", "T. Vladimirescu" );
params.put( "NR", "11" );
params.put( "BL", "V4" );
params.put( "SC", "A" );
params.put( "ET", "1" );
params.put( "AP", "1" );
params.put( "JUDET_DOMICILIU", "Alba" );
params.put( "TIP_ACT", "CI" );
params.put( "SERIA", "Ax" );
params.put( "NR_ACT", "42910" );
params.put( "CNP", "1870301011193" );
params.put( "COR", "Inginer software" );
params.put( "BENEFICIAR", 0 );
params.put( "EVIDENTA", 0 );
params.put( "DATA", "02/08/2012" );
PdfData pdfData = new PdfData();
pdfData.setExportedFileName( "cerereDosar.pdf" );
pdfData.setTemplateName( "reports/cerereDosar.jasper" );
pdfData.setParams( params );
InputStream inputStream = null;
resp.reset();
resp.setHeader( "Content-Type", "application/octet-stream" );
resp.setHeader( "Content-Disposition", "attachment; filename=\"" + pdfData.getExportedFileName() + "\";" );
inputStream = new ClassPathResource( pdfData.getTemplateName() ).getInputStream();
// final Locale locale = FacesContext.getCurrentInstance().getApplication().getDefaultLocale();
// pdfData.getParams().put( JRParameter.REPORT_LOCALE, new Loca );
JasperPrint jasperPrint = JasperFillManager.fillReport( inputStream, pdfData.getParams(),
new JREmptyDataSource() );
JasperExportManager.exportReportToPdfStream( jasperPrint, resp.getOutputStream() );
inputStream.close();
logger.info( req.getQueryString() );
}
catch( Exception e ) {
e.printStackTrace();
}
}
}
和 test.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:nao="http://nao.anofm.org/jsf/composite/util"
xmlns:naocc="http://java.sun.com/jsf/composite/components">
<ui:composition template="/layout/template.xhtml">
<ui:define name="content">
<h:form id="forma">
<a4j:commandButton value="Action" onclick="printTest();" />
<div style="display: none;" id="result"></div>
</h:form>
<script type="text/javascript">
function print(tipAct){
$('<iframe>')
.appendTo('#result')
.attr('src', 'http://localhost:8080/nao-inregistrare/TestServlet/')
.attr('id', tipAct);
}
function printTest(){
for(var i = 1; 5>i; i++){
$.when(print(i)).done();
}
}
</script>
</ui:define>
</ui:composition>
</html>
欢迎任何建议!