java 中拿项目路径

时间:2023-02-07 07:39:02

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}