java 中拿项目路径

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}

原文地址:https://www.cnblogs.com/littleapple/p/10774106.html