如何在Struts 2中获得项目路径? [英] How do you get the project path in Struts 2?
问题描述
例如:
<constant name="struts.multipart.saveDir" value="temp" />
将保存到:
\ Apache Tomcat 7.0.14 \ bin \ temp \ up ____ 781d3178_13831f5e207__8000_00000003.tmp
\Apache Tomcat 7.0.14\bin\temp\upload__781d3178_13831f5e207__8000_00000003.tmp
所以,相反,我该如何去做:
So, instead, how do I make it go to:
C:\ my_project \ build \ web \ temp \
C:\my_project\build\web\temp\
不使用绝对文件路径,因为我不想每次项目移动时都重新配置它.我只想要基本的相对路径.
Without using the absolute file path because I don't want to reconfigure it each time the project moves. I just want the relative path basically.
我认为这并不重要,但我使用的是Struts 2 2.1.8.1版
I don't think it matters, but I'm using Struts 2 version 2.1.8.1
我正在使用Apache Tomcat.那就是我要将项目部署到的地方.没有办法在struts.xml中引用Tomcat的项目部署位置吗?
I'm using Apache Tomcat. That's where I'm deploying the project to. Is there no way to make a reference to Tomcat's project deployment location in the struts.xml?
类似的东西:
<constant name="struts.multipart.saveDir" value="..\webapps\project\build\web" />
推荐答案
有几种方法可以做到这一点.这是最简单的方法:
there are several ways to do this. here is the most easy way:
<constant name="struts.multipart.saveDir" value="${catalina.home}/webapps/project/web/temp"/>
您必须设置 CATALINA_HOME
更新
也许是这样,在您的web.xml中:
maybe this way, in your web.xml:
<context-param>
<param-name>catalina.home</param-name>
<param-value>path/to/your/tomcat</param-value>
</context-param>
更新
我还找到了一个链接,它用于Log4j,但它是相同的. 链接到解决方案
I also found a link, it is for Log4j, but it is the same. Link-To-Solution
这篇关于如何在Struts 2中获得项目路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!