环境:linux
容器:websphere
框架:SSH
描述:最近在做项目的时候发现,在我读取项目文件的时候出错了,而之前在windows平台是好的
解决:后来发现原因是由于在windows和linux下读取当前应用的资源文件有点小区别
windows:basePath=this.getRequest().getRealPath("/")+"XXX"+File.separator+"XXXX"+File.separator;
linux:basePath=this.getSession().getServletContext().getRealPath("/")+File.separator+"XXX"+File.separator+"XXXX"+File.separator;
故加上如下代码
String osName=System.getProperties().getProperty("os.name");
String basePath="";
if("Linux".equals(osName)||"linux".equals(osName)||"LINUX".equals(osName)){
basePath=this.getSession().getSe