【问题标题】:how to get correct path in jsp如何在jsp中获取正确的路径
【发布时间】:2014-04-24 03:55:59
【问题描述】:

我想在 jsp 文件中定义一个路径

<% String paths = "/test/abc.txt"; %>

但它总是向我显示 - 找不到文件错误
我使用的是tomcat8服务器,我的index.jsp文件放在同级别的txt文件中,都在test文件夹里面。

webapps/test/index.jsp
webapps/test/abc.txt

【问题讨论】:

  • 添加完整的异常堆栈跟踪以及您如何读取文件的代码。

标签: jsp path tomcat8


【解决方案1】:

当你的路径在 webapp 上下文中时,使用application.getRealPath("/"):

<% String paths = application.getRealPath("/") + "abc.txt"; %>

【讨论】:

  • 它有效,谢谢,你介意告诉我,如果我把我的东西放在 webapp/ROOT 中,那么如何?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-04-23
  • 1970-01-01
  • 1970-01-01
  • 2016-03-08
  • 1970-01-01
  • 2021-10-25
  • 2010-12-09
相关资源
最近更新 更多