Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string.
Returns the part of this request's URL that calls the servlet. This path starts with a "/" character and includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string. Same as the value of the CGI variable SCRIPT_NAME.
String relativeWebPath = "/file.jpg";
String absoluteDiskPath = getServletContext().getRealPath(relativeWebPath);
File file = new File(absoluteDiskPath);
InputStream input = new FileInputStream(file); // I guess this is what you want.
// ...
# 1 楼答案
你可能正在寻找^{} :
。。。或^{}
# 2 楼答案
你对} 方法感兴趣
HttpServletRequest
的^{# 3 楼答案
那么文件被存储在战争的公共网络内容中了?使用^{}
请注意,这仅在容器扩展战争时有效。否则,如果你真正想要的只是得到^{,最好使用^{}
另请参见: