如何将文件保存到项目外的相对路径?所以我可以在程序运行的任何计算机上创建资源文件夹吗?
我试过了:
String folderPath=getClass().getClassLoader().getResource(".").getPath()+other stuff
创建我保存图像的文件夹路径。它创建了一个像tomcat%20v7.0这样的文件夹,确实保存了我的图像。我为数据库中的每张图片保留绝对路径,然后将它们加载到jsp文件中。在eclipse中运行应用程序时,一切正常。尝试在浏览器中运行时,不会显示照片。 浏览器安装在E:
上的C:和tomcat / eclipse上答案 0 :(得分:-1)
public static List<String> getEndPoints() throws
MalformedObjectNameException,
NullPointerException, UnknownHostException,
AttributeNotFoundException, InstanceNotFoundException,
MBeanException, ReflectionException {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objs = mbs.queryNames(new ObjectName(
"*:type=Connector,*"), Query.match(Query.attr("protocol"),
Query.value("HTTP/1.1")));
String hostname = InetAddress.getLocalHost().getHostName();
InetAddress[] addresses = InetAddress.getAllByName(hostname);
ArrayList<String> endPoints = new ArrayList<String>();
for (Iterator<ObjectName> i = objs.iterator(); i.hasNext();) {
ObjectName obj = i.next();
String scheme = mbs.getAttribute(obj, "scheme").toString();
String port = obj.getKeyProperty("port");
for (InetAddress addr : addresses) {
String host = addr.getHostAddress();
String ep = scheme + "://" + host + ":" + port;
endPoints.add(ep);
}
}
return endPoints;
}
//use above code to get path like "http://yourip:yourport/yourwebapppath"