为我的检票口项目查找相对上传路径



我需要将图片上传到我的网络服务器上的/picture 文件夹。问题是我不知道如何找到将文件复制到的路径。我研究过冰块的例子,但它们使用;

uploadFolder = new Folder(System.getProperty("java.io.tmpdir"), 
               "wicket-uploads");

以查找要将文件复制到的正确文件夹。我需要的是我的 html 文件的路径,以便我可以将/picture 文件夹添加到该路径。有什么提示吗?

您可以使用 ServletContext 的 getRealPath(...) 方法

String realPath = context.getRealPath("pictures");

要获取 ServletContext,请使用可从所有页面访问的 WebApplication 类:

ServletContext context = ((WebApplication) getApplication()).getServletContext();

最新更新