java 中拿项目路径

时间:2020-12-11 20:05:52

public class ItemPathInterceptor extends HandlerInterceptorAdapter {


@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {

request.setAttribute("itemPath", request.getContextPath());

return true;
}
}

或者直接引用 request.getContextPath();

这里的itemPath和前一篇的 ${pageContext.request.contextPath} 是一样的结果,我们可以用${itemPath}