eclipse WebContent下的Struts 2上传文件目的地

blpfk2vs  于 2024-01-07  发布在  Eclipse
关注(0)|答案(2)|浏览(155)

我想把Struts 2上传文件的目的地下的WebContent我的应用程序。
我已经使用了这个方法:

  1. ServletContext context = ServletActionContext.getServletContext();
  2. String uploadFilePath = context.getRealPath("/uploads");

字符串
但是uploadFilePath返回这个

  1. D:\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MyApplication\uploads


我想得到这个返回值

  1. D:\dev\workspace\MyApplication\WebContent\uploads


如何在WebContent下放置Struts2上传文件目的地。我使用Eclipse Juno和Windows7。

hivapdat

hivapdat1#

试试这个

  1. HttpServletRequest request=(HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
  2. String savePath =request.getRealPath("/uploads");
  3. //Here savePath=Application_ROOT_FOLDER\uploads

字符串

hmtdttj4

hmtdttj42#

Struts 2将上载文件放置在为Web服务器指定 * 临时 * 文件夹下您可以将此文件夹中文件复制到收藏夹中

  1. Files.copy(source, target, REPLACE_EXISTING);

字符串
请参阅Java tutorial

相关问题