Java 如何在struts2操作中获取ContextPath?
我在我的项目中使用struts2。必须在我的JSP操作中生成图像,并将其存储在war文件路径中。为此,我必须获得Struts2中的Contextpath。那么,如何获取War文件路径以将图像/文件存储在War文件下的指定文件夹中Java 如何在struts2操作中获取ContextPath?,java,struts2,Java,Struts2,我在我的项目中使用struts2。必须在我的JSP操作中生成图像,并将其存储在war文件路径中。为此,我必须获得Struts2中的Contextpath。那么,如何获取War文件路径以将图像/文件存储在War文件下的指定文件夹中 有人能帮我找到struts2中的Contextpath吗。提前感谢。使用以下代码 public class Page1 extends ActionSupport implements ServletRequestAware { public HttpServlet
有人能帮我找到struts2中的Contextpath吗。提前感谢。使用以下代码
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;
}
}
此代码将起作用非常感谢您的回复!。如何从struts2action获取特定java包的类列表?我正在尝试使用getContextPath(),但获取异常。HttpServletRequest上的getRealPath()现在已被弃用。改为使用request.getServletContext().getRealPath(“/”)。
String path = request.getRealPath("/");