f*n 发帖数: 254 | 1 jboss做server,最基本的servlet,想列出诸如/subfolder1下所有文件
用File f1 = new File("/subfolder1"),但f1.isDirectory()returns false。。。
从而没法再运行list()。
请问应该怎么做?谢谢。。。 |
t*******e 发帖数: 684 | 2 这个和Servlet没什么关系。搞清Java IO的基本操作就可以了。确保path is valid. |
f*n 发帖数: 254 | 3 谢谢,path没有问题,但是有没有什么security设定啊,现在在浏览器里输入
/subfolder1/file.txt可以显示下载,但是输入/subfolder1则显示找不到。。。
【在 t*******e 的大作中提到】 : 这个和Servlet没什么关系。搞清Java IO的基本操作就可以了。确保path is valid.
|
t*******e 发帖数: 684 | 4 You are confused between the directory listing feature of web servers, and
Java IO streaming. |
f*n 发帖数: 254 | 5 thanks... I guess so but cannot find any examples. I followed this but
failed:
http://www.javajunkies.org/index.pl?node_id=3568&lastnode_id=41
【在 t*******e 的大作中提到】 : You are confused between the directory listing feature of web servers, and : Java IO streaming.
|
c********g 发帖数: 449 | 6 I think full path should be used in java servlets.
my codes for your reference:
static final String USER_DIR = "C:\\users\\";
static final String WORK_DIR = "C:\\work\\";
they have been really working on tomcat on Windows. |
c********g 发帖数: 449 | 7 also try File f1 = new File("/subfolder1/");
"/subfolder1" -->"./subfolder1/" |
g*****g 发帖数: 34805 | 8 I think you are confused with relative path. For path
used in web app, normally you have 2 choices.
1. Pass in a root web app directory as a property to the app
2. Use classpath resource and keep your files in $App/classes
That way, you achieve portability.
【在 f*n 的大作中提到】 : 谢谢,path没有问题,但是有没有什么security设定啊,现在在浏览器里输入 : /subfolder1/file.txt可以显示下载,但是输入/subfolder1则显示找不到。。。
|
f*n 发帖数: 254 | 9 明白一点了。也就是说,choice 1需要给出app在server的local directory path是吧。
谢谢。。。
【在 g*****g 的大作中提到】 : I think you are confused with relative path. For path : used in web app, normally you have 2 choices. : 1. Pass in a root web app directory as a property to the app : 2. Use classpath resource and keep your files in $App/classes : That way, you achieve portability.
|
g*****g 发帖数: 34805 | 10 You can put a properties file in classes folder and
configure it whatever way you want.
Typically web application will load some properties file
to do config in startup.
吧。
【在 f*n 的大作中提到】 : 明白一点了。也就是说,choice 1需要给出app在server的local directory path是吧。 : 谢谢。。。
|
f*n 发帖数: 254 | 11 试了一下明白了。谢谢。
【在 g*****g 的大作中提到】 : You can put a properties file in classes folder and : configure it whatever way you want. : Typically web application will load some properties file : to do config in startup. : : 吧。
|