Using Apache commons FileUpload

假如想象 提交于 2019-12-03 21:51:08
File repositoryPath = new File("\\temp");
File uploadedFile = new File("\\applets");

By trying to access these files without any sort of leading or absolute path, you are trying to write to files (not directories) named temp and applets under the current working directory. In an app server, the current working directory is usually the bin folder (depends on what app server you use, etc).

Some suggestions:

  1. Use an absolute path (preferably stored in web.xml or a properties file) to refer to the directory you want to save files to.
  2. You have to specify the name of the file you want to write to, you probably want to create some sort of random/unique name per request.
  3. Save yourself some keystrokes and use a member variable instead of all the Logger.getLogger(UploadGameServlet.class.getName()) references!
  4. Add some debugging, especially to see where you are writing your data to - log the result of repositoryPath.getAbsolutePath(), for example.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!