如何在Web应用程序中获取服务器本地驱动器路径? [英] How to get server local drive path in web application?
问题描述
我正在开发一个jsf Web应用程序,其中已在本地计算机上存储了一些图像文件,例如D:\images
.服务器仅在此计算机上运行.如何在Web应用程序上访问本地驱动器文件.
I am developing a jsf web application in which i have store some image files on my local computer lets say D:\images
. The server running on this computer only. How can i access my local drive files on my web application.
我尝试了
<p:graphicImage value="D:\\Temp\tec0178.jpg">
或
`<p:graphicImage value="D:/Temp/tec0178.jpg">`
这对我不起作用. 如果我将图像放在Web应用程序中
this not work for me. If i place the images in my web application
<p:graphicImage value="resources/images/Male.png"/>
它的工作.
推荐答案
如果需要将其存储在部署了应用程序的服务器上的物理位置上,则可以使用File使用JAVA中的基本I/0操作班级. 本地驱动器可以直接访问.
If you need to store it on a physical location on your server where your application is deployed, you could just work with basic I/0 operations in JAVA using File class. Local drives are directly accessible.
http://docs.oracle.com/javase/tutorial/essential/io /
您也可以探索Google Guava API.
You could also explore Google Guava API for the same.
使用Google Guava API的简单示例是:
A simple example using Google Guava API is:
File imageFile = new File("D:\\images", imgFileName);
FileOutputStream outputStream = new FileOutputStream(newAttachment);
ByteStreams.copy(inputStream, outputStream);
此外,要通过URL访问图像,您必须将目录添加为上下文.查看博客文章,以URL形式访问图像文件:
Also, to access images over URL you'll have to add the directory as context. Check out the blog post to access image file as URL:
http://th1rty7. blogspot.in/2009/05/tomcat-is-通常被认为是be.too.html
这篇关于如何在Web应用程序中获取服务器本地驱动器路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!