我的Web应用程序允许Web管理员将文件上传到服务器,并将此文件命名为“输入文件名和输入文件”。在文件页面上,用户可以单击文件名并获取管理员上载的文件。我的问题是我如何上传文件并使用XML获取输入的名称。我知道如何使用JSP / servlet将文件上传到服务器我只需要将文件名与上传到服务器的文件链接
谢谢
答案 0 :(得分:1)
在服务器中保存文件时,您将创建一个新文件。您可以选择在此处设置名称。
String fileName = request.getParameter("fileName");
File baseDir = new File("/path/to/save/the/files/");
File file = new File(baseDir, fileName);
//here you receive the InputStream that holds the data from the file uploaded
//since I don't know how you're retrieving it, I'll put three dots
InputStream inputStream = ...
//save the file in disk...