简体   繁体   English

如何在CentOS中从一个应用程序到另一个应用程序获取Java中的tomcat Web绝对路径?

[英]How to get the tomcat web absolute path in java from one application to the other application in centos?

My tomcat have two web application called webstock and webstockapi .And both of then have a fold called imgfold . 我的tomcat有两个名为webstock和webstockapi的 Web应用程序,然后两个都有一个名为imgfold的折叠。 Each time I called the api and I upload the image file to the path 'webstockapi/imgfold' ,I have to copy them to the other path 'webstock/imgfold' .How to get the web absolute path of webstock when I called the api of webstockapi.In fact my web absolute path is " /application/tomcat/webapps/webstockapi " and " /application/tomcat/webapps/webstock ". 每次我调用api并将图像文件上传到路径'webstockapi/imgfold' ,都必须将它们复制到另一个路径'webstock/imgfold' 。如何在调用api时获取'webstock/imgfold'的网络绝对路径实际上,我的Web绝对路径是“ / application / tomcat / webapps / webstockapi ”和“ / application / tomcat / webapps / webstock ”。 Now I have think a way,but it is complex,and it must have a simple way. 现在我想了一个方法,但是它很复杂,而且必须有一个简单的方法。

//get the imgfold path when I call the webstockapi application
String uploadDir = session.getServletContext().getRealPath("/imgfold");
//my complex way to get the other appliction path
String destinationPicUrl=new File(session.getServletContext().getRealPath("/")).getParent()+
                     File.separatorChar +"webstock"+ File.separatorChar +"imgfold";

How can I get the web absolute path according to the publish web application name directly ? 如何直接根据发布的Web应用程序名称获取Web绝对路径?

It's bad practice to upload into a webapplication's folder - if for nothing else than making backups incredibly hard. 上载到Web应用程序的文件夹是个坏习惯-如果要做的仅仅是使备份变得异常困难,那是不对的。 As soon as you update your webapp, all of the content will be deleted and replaced with your updated webapp. 一旦您更新了Webapp,所有内容将被删除并替换为更新后的Webapp。 Also, no application server guarantees that a web application is even stored in a writeable folder. 同样,没有应用程序服务器可以保证Web应用程序甚至存储在可写文件夹中。 For security reasons alone this is a bad idea (For example: If someone uploads JSP files into a folder within the web application, tomcat will happily execute any uploaded code in that JSP) 仅出于安全性考虑,这是一个坏主意(例如:如果有人将JSP文件上传到Web应用程序内的文件夹中,tomcat将很乐意执行该JSP中所有已上传的代码)

Configure both applications to store data in a folder separate from the application. 配置两个应用程序以将数据存储在与应用程序分开的文件夹中。 That folder can be part of your backup strategy. 该文件夹可以成为备份策略的一部分。 If both point to the same folder, there's no more need to copy files back and forth. 如果两者都指向同一个文件夹,则不再需要来回复制文件。 Then write a simple download servlet that makes the images available to the world, without the risk of server-side code execution. 然后编写一个简单的下载servlet,使图像可供世界使用,而无需执行服务器端代码。 There are plenty of samples for Download servlets everywhere - choose one that's hardened against traversing random folders and just returns data from the configured one. 到处都有许多用于下载servlet的示例-选择一种针对遍历随机文件夹进行加固的示例,仅从已配置的servlet返回数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Web应用程序中获取tomcat / glassfish使用的Java路径的任何方法 - Any way to get java path used by tomcat/glassfish in web application 如何在Web应用程序的Java类中给出绝对的“文件路径”? - How to give absolute “file-path” in a java class of a web application? 如何获取Java Web应用程序中正在运行的.exe的绝对路径? - How can I get the absolute path of a running .exe in java web application? 使用 spring 重新映射 web 应用程序 (tomcat) 中的图像请求以获得绝对路径 - Remap image requests in a web application (tomcat) with spring for an absolute path 获取Eclipse项目的绝对路径(在使用tomcat服务器的Web应用程序中) - getting eclipse project absolute path (in web application using tomcat server) 如何获取Java Web应用程序路径? - How to get Java web application path? Java Web应用程序,tomcat 6 - Java Web application ,tomcat 6 如何在Tomcat中获取应用程序路径(不是从Servlet上下文中获取) - How to get Application Path in Tomcat (not from a Servlet context) 如何在tomcat上部署Java Web应用程序(.war)? - How to deploy a Java Web Application (.war) on tomcat? Java Web Start ExtensionInstallerService-如何掌握应用程序中的安装路径? - Java Web Start ExtensionInstallerService - How to get hold of the install path in the application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM