2017-02-03 22 views
0

或者至少我認爲問題在於...
在下面的第一行中,日誌表示流不爲空
在第二行中表示在錯誤堆棧跟蹤的開始處爲空:struts.xml執行得不好嗎?

01/02 07:30:07| INFO [http-apr-10080-exec-6] (BillAction.java:704) - completeExport() - [email protected] 
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) 
etc... etc... 

這是產生這種結果的代碼:

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> 

exportBillToExcel():

public String exportBillToExcel() { 
    XSSFWorkbook myWorkBook = new XSSFWorkbook(); 
    XSSFSheet mySheet = myWorkBook.createSheet(categ); 
    try { 

    ... etc. body of the method ... etc... 

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

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> 

completeExport():

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

和自然中的類存在InputStream的聲明和get和set方法。

我在哪裏錯了?

回答

0

您能否顯示您的getInputStream()方法?也許有一些錯誤。文件下載不需要setInputStream()方法。

順便說一下:輸入流在會話中的「停放」有點尷尬。我不確定這是否有效。我想你必須在completeExport()方法中創建inputStream。

0

嘗試定義結果類型,流的struts.xml

<action name="exportExcelBill" 
    class="it.colmenjv.dlq.actions.BillAction" 
    method="exportBillToExcel"> 
    <interceptor-ref name="loginStack" /> 
    <result type = "stream"> 
     <param name="inputName">tmpstream</param> 
    </result> 
    <result name="login">timeout.jsp</result> 
    <result name="success">jsp/common/intermeanExcel.jsp</result> 
</action> 

沒有必要把tmpstream對象到會話Java類。由於我們已經在結果中定義了tmpstream,因此可以通過jsp訪問。

相關問題