小弟做了个导出,可是怎么都弄不出自定义保存地址来,请大家指导一下啊
这是我的配置文件及代码:
<action name="excel" class="com.nbc.message.client.action.ExportMessageAction">
<result name="excel" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="inputName">excelStream</param>
<param name="contentDisposition">attachment;filename=" ${fileName}.xls"</param>
<param name="bufferSize">1024</param>
</result>
</action>
页面
<body>
<h1>导出</h1>
<form action="<%=request.getContextPath()%>/send/excel.action" method="post" ><input name="submit" type="submit" value="submit" /></form>
</form></body>
代码;
public InputStream getExcelInputStream() throws IOException {
HSSFWorkbook hk = new HSSFWorkbook();
HSSFSheet hssfSheet = hk.createSheet("new sheet");
HSSFRow hRow = hssfSheet.createRow(0);
HSSFCell cell = hRow.createCell(0);
cell.setCellValue("中国");
ByteArrayOutputStream bs = new ByteArrayOutputStream();
hk.write(bs);
ByteArrayInputStream asArrayInputStream = new ByteArrayInputStream(bs.toByteArray());
return asArrayInputStream;
}
这是我的配置文件及代码:
<action name="excel" class="com.nbc.message.client.action.ExportMessageAction">
<result name="excel" type="stream">
<param name="contentType">application/vnd.ms-excel</param>
<param name="inputName">excelStream</param>
<param name="contentDisposition">attachment;filename=" ${fileName}.xls"</param>
<param name="bufferSize">1024</param>
</result>
</action>
页面
<body>
<h1>导出</h1>
<form action="<%=request.getContextPath()%>/send/excel.action" method="post" ><input name="submit" type="submit" value="submit" /></form>
</form></body>
代码;
public InputStream getExcelInputStream() throws IOException {
HSSFWorkbook hk = new HSSFWorkbook();
HSSFSheet hssfSheet = hk.createSheet("new sheet");
HSSFRow hRow = hssfSheet.createRow(0);
HSSFCell cell = hRow.createCell(0);
cell.setCellValue("中国");
ByteArrayOutputStream bs = new ByteArrayOutputStream();
hk.write(bs);
ByteArrayInputStream asArrayInputStream = new ByteArrayInputStream(bs.toByteArray());
return asArrayInputStream;
}
改成
getInputStream<param name="contentDisposition">attachment;filename=" ${fileName}.xls"</param>
文件名写死试试看?
<param name="contentDisposition">attachment;filename="output.xls"</param>
InputStream excelStream;
private String fileName;
public String execute() throws Exception{
IExcelService es = new IExcelServiceImpl();
excelStream = es.getExcelInputStream(); return "excel";
} public InputStream getExcelStream() {
return excelStream;
} public void setExcelStream(InputStream excelStream) {
this.excelStream = excelStream;
} public String getFileName() {
return fileName;
} public void setFileName(String fileName) {
this.fileName = fileName;
} }
public class IExcelServiceImpl implements IExcelService { public InputStream getExcelInputStream() throws IOException {
HSSFWorkbook hk = new HSSFWorkbook();
HSSFSheet hssfSheet = hk.createSheet("new sheet");
HSSFRow hRow = hssfSheet.createRow(0);
HSSFCell cell = hRow.createCell(0);
cell.setCellValue("中国");
ByteArrayOutputStream bs = new ByteArrayOutputStream();
hk.write(bs);
ByteArrayInputStream asArrayInputStream = new ByteArrayInputStream(bs.toByteArray());
return asArrayInputStream;
}