在struts2中隐藏加载器(旋转)

时间:2017-01-28 18:31:24

标签: css struts2 loader

我的Web应用程序(struts2)查询通常很繁琐,并且需要相当长的时间来进行响应。

我添加了一些简单的(只是一个html DIV和一些CSS)在动作调用后等待。 a whirligig like this

旋转旋转,当达到动作目标时,加载一个新的jsp并且旋转消失。

当被调用的动作是一个下载excel文件等数据的动作时出现问题(我想,即使还没有尝试过,对于pdf,文件上传等......在这种情况下,新的JSP不需要加载)。

加载完成后,我无法找到停止或隐藏旋转的方法。

当窗口开始下载文件时,我尝试使用onblur事件(应用于旋转div,容器div,整个窗口等等)来停止微调器。

所以,我认为加载文件时系统窗口不被浏览器视为真正的窗口,所以事件" onblur"毫无意义!

最后,当创建excel文件时,或者只是在系统加载窗口关闭(或打开)时,如何在响应开始时隐藏旋转?

2 个答案:

答案 0 :(得分:0)

将下载操作分为两个操作。第一个应该返回成功的javascript,第二个,step2,action应该返回成功的流,如下所示:

step1.jsp

<script> $(document).ready(function() {
closeBoxWait(previous_boxWait);
window.location = '<s:url namespace="/" action="step2"/>';
}); </script>

struts.xml中

<action name="exportExcelBill" 
    class="jj.colmenjv.dlq.actions.BillAction"
    method="exportBillToExcel">

    <interceptor-ref name="loginStack" />
    <result name="login">timeout.jsp</result>

    <result name="success">step1.jsp</result>
</action>
<action name="step2" 
    class="jj.colmenjv.dlq.actions.BillAction"
    >

    <result name="success" type="stream">
        <param name="contentDisposition">attachment;filename="${reportFile}"</param>
        <param name="contentType">application/vnd.ms-excel</param>
        <param name="inputName">inputStream</param>
        <param name="bufferSize">1024</param>
    </result>
</action>

答案 1 :(得分:0)

前提 - 我希望能够做到这一点,并且这是允许添加回复的情况之一。
前提2 - 我不是Struts2中的魔术师(但那已经很清楚了,不是吗?)

Thanx Yasser,我尝试了你宝贵的建议,但我很难过:
这是我的新struts.xml

    <action name="exportExcelBill" 
        class="it.colmenjv.dlq.actions.BillAction"
        method="exportBillToExcel">
        <interceptor-ref name="loginStack" />
        <result name="login">timeout.jsp</result>
        <result name="success">jsp/common/intermeanExcel.jsp</result>
    </action>
    <action name="completeExport" 
        class="it.colmenjv.dlq.actions.BillAction"
        method="completeExport">
        <interceptor-ref name="loginStack" />
        <result name="login">timeout.jsp</result>
        <result name="success" type="stream">
            <param name="contentDisposition">attachment;filename="${reportFile}"</param>
            <param name="contentType">application/vnd.ms-excel</param>
            <param name="inputName">inputStream</param>
            <param name="bufferSize">1024</param>
        </result>
    </action>

这是intermeanExcel.jsp:

<head>
    <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="js/common/common.js"></script>
</head>

<body>
    <%@ include file="./warningwait.jsp" %>

     <script> 
         $(document).ready(function() {
                                        closeBoxWait(previous_boxWait);
                                        window.location = '<s:url namespace="/" action="completeExport"/>';
                                    }); 
    </script>   
</body>

我在原始方法(exportBillToExcel)中添加了一行(倒数第二行),以便在会话中放置数据流

public String exportBillToExcel() {
    XSSFWorkbook myWorkBook = new XSSFWorkbook();
    XSSFSheet mySheet = myWorkBook.createSheet(categ);
    try {
等等......我省略了 - 对于这个问题不必要 - 方法的主体运作良好,独立时等等......

    }
    catch (Exception e) {
        e.printStackTrace();
    }
===>    session.put("tmpstream", inputStream);
    return SUCCESS;
}

以便在新方法中恢复它

public String completeExport() {
    inputStream = (InputStream)session.get("tmpstream");
    logger.info("completeExport() - inputStream="+inputStream);
    return SUCCESS;
}

但这是错误日志(即使-first row-流不为null):

01/02 07:30:07| INFO [http-apr-10080-exec-6] (BillAction.java:704) - completeExport() - inputStream=java.io.ByteArrayInputStream@11d1921
01/02 07:30:07| ERROR [http-apr-10080-exec-6] (CommonsLogger.java:34) - Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified f
or this action.
01/02 07:30:07| ERROR [http-apr-10080-exec-6] (CommonsLogger.java:38) - Exception occurred during processing request: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Chec
k the <param name="inputName"> tag specified for this action.
java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
        at org.apache.struts2.dispatcher.StreamResult.doExecute(StreamResult.java:237)
        at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
        at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:367)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:271)
        at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
        at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
        at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
        at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
        at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
        at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
        at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)

我错了吗?

PS - 隐藏微调器的作品!感谢名单!