/* 第一种:在 Struts2 当中,Struts1同样也可通过这种形式获取: */
/* 获取 request 对象 */
HttpServletRequest request = ServletActionContext.getRequest();
/* 得到当前上下文绝对路径以保存图片 */
String contextPath = request.getSession().getServletContext().getRealPath("//");
/* 第二种:在 Filter 当中: */
public void init(FilterConfig config) throws ServletException {
/* 可将此参数放入到 Session 可供全局使用 */
String contextPath = config.getServletContext().getRealPath("//");
}
/* 第三种 */
String contextPath = request.getScheme()+"://"+request.getServerName() +":"+request.getServerPort()+request.getContextPath()+"/";
JAVA 得到上下文绝对路径
最新推荐文章于 2024-04-15 08:00:00 发布