request.getRealPath("/") 在window获取的是服务器的根目录,结尾包含分隔符,

如E:\apache-tomcat-6.0.29-bak\apache-tomcat-6.0.29\apache-tomcat-6.0.29\webapps\test\

在Linux下获取的不含分隔符,如:

/home/weblogic/Desktop/PTYT/ptytNetpay/WebRoot

因此需要判断处理:

String root = request.getRealPath("/"); 
  if (!root.endsWith(java.io.File.separator)) {
        root = root + java.io.File.separator;
        }

 最后 : request.getRealPath() 方法已经不推荐使用,推荐使用 request.getSession().getServletContext().getRealPath("/");

相关文章:

  • 2021-11-28
  • 2021-11-20
  • 2021-06-25
  • 2021-06-24
  • 2022-02-02
  • 2022-02-07
  • 2021-11-29
猜你喜欢
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2021-11-12
  • 2021-12-18
相关资源
相似解决方案