在WEB项目(Spring + Struts2 + MyBatis)中定义了一个 ACTION 类如下:
@Component("actReportCheck")
@Scope("prototype")
public class ActReportCheck {
}
我不知道该如何获取 request ,并进一步获取系统的URL地址。
答案在这里:
http://www.chinaitlab.com/Java/Struts/940926.html
实现 ServletRequestAware 接口,并实现接口中的 setServletRequest 方法
@Component("actReportCheck")
@Scope("prototype")
public class ActReportCheck implements ServletRequestAware {
----------------------------------------------------------------------
logger.info(request.getSession().getServletContext().getRealPath(""));
// 输出:[INFO ] C:\Java\Tomcat7\webapps\VIMSystem
@Component("actReportCheck")
@Scope("prototype")
public class ActReportCheck {
…
}
我不知道该如何获取 request ,并进一步获取系统的URL地址。
答案在这里:
http://www.chinaitlab.com/Java/Struts/940926.html
实现 ServletRequestAware 接口,并实现接口中的 setServletRequest 方法
@Component("actReportCheck")
@Scope("prototype")
public class ActReportCheck implements ServletRequestAware {
private HttpServletRequest request;
@Override
public void setServletRequest(HttpServletRequest arg0) {
// TODO Auto-generated method stub
this.request = arg0;
}
…
}
----------------------------------------------------------------------
logger.info(request.getSession().getServletContext().getRealPath(""));
// 输出:[INFO ] C:\Java\Tomcat7\webapps\VIMSystem