English 中文(简体)
Servlet/Tomcat relative file path
原标题:Servlet/Tomcat relative file path

www.un.org/spanish/ecosoc 在什么地方将档案列入Tomcat Servlet的申请中,这些档案在网页上相对可见?

More detail: I am developing a servlet page while using an external library. That library depends massively on external loaded XML files (relative file paths). So I need to put these XML files in the running directory of the servlet.

Tomcat服务器是否有办法可检索relatively?

问题回答

当网络应用程序部署到Tomcat时,网络应用的根基是CATALINA_HOME/webapps/YOUR_WEB_APP/

因此,如果使用一个服务器,在你网络应用的根基里,可以查阅XML文件,那么你就只能使用:

request.getServletContext().getResourceAsStream("PATH/TO/YOUR/XML_FILE.xml")

将把XML文档作为InputStream。 当然,如果你想要查阅档案本身,你可以始终使用<条码>植被资源(编码资源)方法获取<条码>URL,从中获取<代码>File物体(替代方法包括):

File f;
try {
  f = new File(url.toURI());
} catch(URISyntaxException e) {
  f = new File(url.getPath());
}

EDIT: 使其相对可见于网络浏览器,简单地将其从WWEB-INF和MEA-INF目录中删除。

如果你谈到这个图书馆,你将搜寻该年级的档案(如Hibernate或Log4J会这样做),你就必须将XML档案列入WEB-INF。 然而,我建议你不要人工这样做。 你可以把档案放在你申请的源头目录中,这将确保档案在正确的地点部署。

这是一个老的问题。 页: 1 我很成功地把托马托克安装台作为基地。 (CATALINA_HOME) 举例来说,从网上查阅档案的相对途径是“网站/ROOT/aboutDir/fileName”

反复回答的抱怨地点是处理一再提出的问题。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签