Java 导出excel并防止用户在完成之前重新处理操作的操作方法

Java 导出excel并防止用户在完成之前重新处理操作的操作方法,java,excel,struts2,export,action,Java,Excel,Struts2,Export,Action,我试图编写一个操作方法来导出excel,同时防止用户在处理过程中调用该操作 问题在于,当我重新单击“提交(导出)”按钮时,要导出的excel内容将显示在网页上,而当导出完成时,我有以下例外情况: rg.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [default] in context with path [/myApp] threw exception ja

我试图编写一个操作方法来导出excel,同时防止用户在处理过程中调用该操作

问题在于,当我重新单击“提交(导出)”按钮时,要导出的excel内容将显示在网页上,而当导出完成时,我有以下例外情况:

rg.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [default] in context with path     [/myApp] threw exception
java.lang.RuntimeException: org.apache.jasper.JasperException: An exception occurred processing JSP page /decorators/main.jsp at line 48
我将此代码用于我的操作方法:

@Action(value = "exportExcelMdt", results = {

        @Result(name = "exportExcel", 
                type = "stream", 
              params = { "inputName", "inputStream", 
                       "contentType", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 
                "contentDisposition", "attachment;filename=${filename};", 
                        "bufferSize", "1024" }),

        @Result(name = "success", 
                type = ActionSupport.NONE) 
})

public String doExportExcel() {

    Boolean exportPending = (Boolean) this.session.get(EXPORT_EXCEL);
    if (exportPending == null) { // this is used as a semaphore to prevent the user from re-calling the export action (server-side of course)
        try {
            this.session.put(EXPORT_EXCEL, Boolean.TRUE);
            logger.debug("export excel...");
            this.filename = this.getText("myApp.message.mandat.recherche.extraction.filename");
            this.inputStream = this.extractExcel(this.searchResults(false)); // this will just get the related beans and write the excel file using Apache POI
            return "exportExcel";
        } catch (Exception e) {
            logger.debug("export excel erreur...");
        } finally {
            this.session.remove(EXPORT_EXCEL);
        }
    } else {
        //          this.addActionMessage("An export excel is already running !");
    }

    return SUCCESS;
}
调用操作的JSP代码:

函数insertExcelButtonForExtraction(){
//creer le nom depuis“#gview”+l'id de la grid
变量$btnExcel=$(“#gview_resultGrid>div>#btnExcel”);
//检查对象是否已经存在
如果(!$btnExcel.length){
var$a=$(“#gview_resultGrid>div>a”);
var$newA=$a.clone();
$newA.attr('style','right:25px;padding top:2px;');
$newA.attr('id','btnExcel');
$newA.children(“span”).remove();
$newA.append($('');
$newA.insertAfter($a);
}
}
//导出excel
函数exportExcel(){
$(“#searchForm”).attr(“action”、“exportExcelMdt.action”);
$(“#搜索表单”).submit();
}
以下是相关的struts.xml文件:


真的
错误
搜寻*
dojo\.*,^struts\*
真的
错误
dojo\.*,^struts\*
输入,返回,取消
/jsp/view/error/error.jsp
/Login.action
安全/访问/访问被拒绝。操作
/

似乎提供了您所需的

似乎提供了您所需的

第一次呈现是否正常?我们需要更多代码、struts.xml、操作定义、jsp代码段。。。棘手的问题btw@RomanC:是的,如果我只单击一次,它将正常呈现,并且我可以下载我的excel文件。@Andrea Ligios:我添加了更多信息(jsp、struts.xml和一些关于操作的细节)。有时间的话,请看一看,让我知道你的想法。
name=“success”,type=ActionSupport。没有一个看起来有点奇怪。只需返回
none
。已经这样做了:D常量等于“none”,结果相同:(它是第一次正常呈现吗?我们需要更多的代码、struts.xml、动作定义、jsp代码片段……棘手的问题btw@RomanC:是的,如果我只单击一次,它就会正常呈现,并且我可以下载我的excel文件。@Andrea Ligios:我添加了更多信息(jsp、struts.xml和有关操作的一些详细信息)。请在有时间的时候看一看,并让我知道您对它的看法。
name=“success”,type=ActionSupport。NONE
看起来有点奇怪。只需返回
NONE
。已经这样做了:D常量等于“NONE”,结果相同:(我确实看到了这一点,问题是我需要保持在同一页上,并有一些正在加载的内容(一个弹出窗口;可能是gif)完成后,它应该显示一个弹出式语句。我想我应该考虑一个客户端解决方案。我确实看到了这个问题,问题是我需要停留在同一个页面上,有一些东西正在加载(弹出;GIF可能)。完成后,应该显示一个弹出式语句。我想我应该考虑客户端解决方案。