/* 第一种:在 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()+"/";
发表于 @ 2009年01月22日 08:36:00 | 评论( loading... ) | 编辑| 举报| 收藏