2009-04-14
struts.xml配置
<action name="userexcel" class="com.boentel.user.UserExcelAction">
<result name="outexcel" type="stream">
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${fileNames}"</param>
</result>
<interceptor-ref name="fileUpload"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
Action代码 UserExcelAction
protected String fileNames;
protected String filePathName;
//防止文件名乱码
public String getFileNames() throws Exception{
return new String(fileNames.getBytes(), "ISO8859-1");
}
public void setFileNames(String fileNames) {
this.fileNames = fileNames;
}
public String getFilePathName() {
return filePathName;
}
public void setFilePathName(String filePathName) {
this.filePathName = filePathName;
}
---------------------不能少---------------------
public InputStream getInputStream() throws Exception
{
return new FileInputStream(new File(getFilePathName()));
}