java - 如何在 struts2 Action 中获取 ContextPath?

标签 java 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;  
    }
}

关于java - 如何在 struts2 Action 中获取 ContextPath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9372106/

相关文章:

java - Struts 2 类型转换器问题

java - 使用spring AOP切面拦截方法?

java - 在 Hibernate 3.6.10.Final + c3p0 + struts2 中打开新连接时关闭连接

linux - pdf = rs.getBytes ("pdf");它在 Windows 操作系统中不起作用。从 postgres bytea 字段读取二进制数据的替代方法是什么

java - 未捕获的类型错误 : Cannot read property 'length' of undefined while accessing arraylist through Json Object

Java Struts 标签迭代器在大列表上挣扎

java - Java中判断何时没有按键

java - 如何确定数据库的 URL?

java - Android JSON 对象创建

java - 如何加载 jar 文件以在 Jython 中进行调试?