web项目部署linux找不见模板excel的文件

Linux系统和windows系统的路径有区别

  1. 项目中获取模板excel的路径
// 获取模板文件路径
String tempPath = request.getSession().getServletContext().getRealPath("/")
				+ "\\file\\download\\error_import_AssetInfo.xlsx";
  • 使用\拼接在windows系统中可以找到,但是在linux中则不行。
  • linux识别的路径为:
/usr/local/java/tomcat/tomcat8.5/webapps/ias/\file\download\error_import_AssetInfo.xlsx (No such file or directory)

解决办法:
使用File.separator进行拼接。如下:

// 获取模板文件路径
	String tempPath = request.getSession().getServletContext().getRealPath("/")
	+File.separator+ "file"+File.separator+"download"+File.separator+"assetInfo.xlsx";

excel表格导出B/S和C/S的区别

B/S架构的项目,excel表格导出需要转成response的流。
下面是B/S模式中采用的输出方式,而不是输出到本地指定的磁盘目录。该代码表示将details.xls的Excel文件通过应答实体(response)输出给请求的客户端浏览器,客户端可保存或直接打开。

//输出Excel文件
    OutputStream output=response.getOutputStream();
    response.reset();
    response.setHeader("Content-disposition", "attachment; filename=details.xls");
    response.setContentType("application/msexcel");        
    wkb.write(output);
    output.close();

C/S架构的项目,excel表格导出可以指定导出的本地系统的路径。

File file=new File("D://temp.xls");
WritableWorkbook wwb = Workbook.createWorkbook(file);

参考的博客:https://www.cnblogs.com/hanfeihanfei/p/7079210.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值