String directory = "/upload";
String targetDirectory = ServletActionContext.getServletContext().getRealPath(directory);
targetDirectory 路径是指eclipse 工作目录下
*\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp4\wtpwebapps\Exercise\upload
若是发现路径中包含了web服务器的路径,那你就要采用截串的办法,将路径定位到相对路径下。

本文介绍了如何使用ServletActionContext获取上传文件的绝对路径,并提供了一个实际的代码示例。此外,还讨论了当路径中包含web服务器的具体路径时,如何通过截取字符串的方式将其转换为相对路径。
4152

被折叠的 条评论
为什么被折叠?



