且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java Servlet下载文件

更新时间:2023-12-03 22:53:16

我更改了它,因此采用了绝对路径,例如

I changed the it so an absolute path is taken e.g.

File f = new File("C:\\data\\" + fileName);

这有效.在Servlet中使用它是否会更改它,以便需要绝对路径并使相对路径不可用?我测试了servlet外部的下载部分,它可以使用相对路径,或者如果未指定任何内容,则可以下载到项目文件夹中.

This works. Does having it in a servlet change it so an absolute path is needed and render relative paths unusable? I tested the downloading part outside of a servlet and it works with relative paths or it just downloads into project folder if nothing is specified.