Strtuts2 导出Excel

 <action name="contractBalanceExport" class="com.inetpsa.pab.actions.accounting.contractbalance.ContractBalanceAction" method="export">
            <result name="success" type="stream">
                <param name="contentType">text/plain</param>
                <param name="inputName">exportStream</param>
                <param name="contentCharSet">UTF-8</param>
                <param name="contentDisposition">attachment;filename="${exportFileName}"</param>
                <param name="bufferSize">10240</param>
            </result>
            <result name="error" type="redirectAction">contractBalanceAction</result>
        </action>

 

 private void exportContractBalanceByCvs(Map<String, Object> titlesMap, Map<String, Object> params, Collection<SimpleContractScreenPO> contracts)
            throws UnsupportedEncodingException {
        StringBuilder exportContent = new StringBuilder();

        // export the searching information filtering information,
        exportContent.append(System.getProperty(SfjConstants.LINE_SEPARATOR));
       
        exportFileName = "contract_balance_" + dftime.format(new Date()) + SfjConstants.SEPARATOR_DOT + CSV;
        exportStream = new ByteArrayInputStream(exportContent.toString().getBytes(SfjConstants.CHARSET_ISO_8859_1));
    }

 

public static final String LINE_SEPARATOR = "line.separator";

 

你可能感兴趣的:(struts)