Redian新闻
>
servlet读取directory的基本问题
avatar
servlet读取directory的基本问题# Java - 爪哇娇娃
r*h
1
ZT:
We need a customer service rep. $15/hr. If you are interested, please apply
at www.np-world.com
• Customer Service - Part Time
• Dallas/Ft. Worth, United States
• English
• 2008/01/19
Base Pay: 15 (USD)/per Hour
Duration: 10 Hour(s)
Project Requirement: Must be professional and have computer, MS Office 2000/
2003 and high speed Internet service.
Project Summary: Assist company with special projects using Microsoft Office
Word, Excel, Powerpoint, Publisher
avatar
f*n
3
jboss做server,最基本的servlet,想列出诸如/subfolder1下所有文件
用File f1 = new File("/subfolder1"),但f1.isDirectory()returns false。。。
从而没法再运行list()。
请问应该怎么做?谢谢。。。
avatar
t*e
4
这个和Servlet没什么关系。搞清Java IO的基本操作就可以了。确保path is valid.
avatar
f*n
5
谢谢,path没有问题,但是有没有什么security设定啊,现在在浏览器里输入
/subfolder1/file.txt可以显示下载,但是输入/subfolder1则显示找不到。。。

【在 t*******e 的大作中提到】
: 这个和Servlet没什么关系。搞清Java IO的基本操作就可以了。确保path is valid.
avatar
t*e
6
You are confused between the directory listing feature of web servers, and
Java IO streaming.
avatar
c*g
8
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.
avatar
c*g
9
also try File f1 = new File("/subfolder1/");
"/subfolder1" -->"./subfolder1/"
avatar
g*g
10
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则显示找不到。。。

avatar
f*n
11
明白一点了。也就是说,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.

avatar
g*g
12
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是吧。
: 谢谢。。。

avatar
f*n
13
试了一下明白了。谢谢。

【在 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.
:
: 吧。

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。