我在我的项目中使用 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;
}
}
关于java - 如何在 struts2 Action 中获取 ContextPath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9372106/