【发布时间】:2012-02-21 04:17:38
【问题描述】:
我在我的项目中使用 struts2。必须在我的 JSP 操作中生成图像并将其存储在 war 文件路径中。为此,我必须在 Struts2 中获取 Contextpath。那么如何获取WAR文件路径来存储WAR文件下指定文件夹中的图片/文件呢?
谁能帮我在struts2中找到上下文路径。提前致谢。
【问题讨论】:
我在我的项目中使用 struts2。必须在我的 JSP 操作中生成图像并将其存储在 war 文件路径中。为此,我必须在 Struts2 中获取 Contextpath。那么如何获取WAR文件路径来存储WAR文件下指定文件夹中的图片/文件呢?
谁能帮我在struts2中找到上下文路径。提前致谢。
【问题讨论】:
使用下面的代码...
public class Page1 extends ActionSupport implements ServletRequestAware {
public HttpServletRequest request;
@Override
public String execute() {
String contextPath = request.getContextPath();
System.out.println("Context Path " + contextPath);
return SUCCESS;
}
@Override
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
}
【讨论】:
String path = request.getRealPath("/");
此代码将起作用
【讨论】: