Tomcat Java 应用程序中的 #define STRING 等效项
我有一个 tomcat 应用程序,需要写入特定目录中的文件,该目录根据应用程序的部署位置(Windows 主机 v linux 主机等)而有所不同。
需要知道文件位置的类对象是一个 Exception 类,我不想将 ServletContext 对象从 JSP 一直传递到这个已编译的 Java 类对象。
我希望能够将文件位置指定为应用程序 context.xml 文件中的参数字符串,然后根据我部署此应用程序的位置来注释或取消注释正确的位置,但我可以'我似乎弄清楚如何从 Tomcat Web 应用程序中编译的 Java 类中访问字符串参数对象。我希望它与我从 InitialContext 对象访问数据源对象的方式类似,但到目前为止还没有运气从中获取 String 对象......
感谢您的帮助!
I have a tomcat app that needs to write to a file in a particular directory that is different depending on where the application is deployed (windows host v linux host, etc..).
The class object that needs to know the file location is an Exception class and I don't want to have to pass the ServletContext object from the JSP all the way down to this compiled Java class object.
I'd like to be able to just have the file location specified as a parameter string in the applications context.xml file and then just comment or un-comment the correct one depending on where I'm deploying this app, but I can't seem to figure out how I can access a string parameter object from within my compiled Java class in the Tomcat webapp. I'm hoping it is something similar to how I access data source objects from the InitialContext object, but have had no luck so far getting a String object out of that...
Your help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与写入文件有关的异常似乎很奇怪。我希望这是一个例外的记录器的工作。您可以通过servlet上下文配置记录器,当抛出异常时,相应地记录异常。
如果您确信您的设计是合适的,也许您可以向我们提供更多有关它的详细信息。
It seems odd for an exception to be concerned with writing to a file. I'd expect that to be the job of a logger which is given the exception. You can configure the logger via the servlet context, and when the exception is thrown, log the exception accordingly.
If you're convinced that your design is appropriate, perhaps you could give us more details about it.