我想知道在 DWR 和 Spring Application 中获取 HttpServletRequest 对象的正确方法是什么 - 我正在尝试执行以下操作:
private HttpServletRequest getRequest() {
ServletRequestAttributes servletAttributes =
(ServletRequestAttributes) RequestContextHolder
.getRequestAttributes();
// this is Spring application's DispatcherServlet call
if (servletAttributes != null) {
return servletAttributes.getRequest();
} else {
if (WebContextFactory.get() == null) {
// non-HttpRequest call
return null;
} else {
// dwr call
return WebContextFactory.get().getHttpServletRequest();
}
}
}
我问这个是因为当这个方法用完任何 http 上下文时,方法 WebContextFactory 会记录以下警告:
WARN org.directwebremoting.WebContextFactory:39 - Missing WebContextBuilder. Is DWR setup properly?
我可能缺少可以判断此方法调用是否在 HttpServletRequest 中的方法,因此我可以直接返回 null 值:
private HttpServletRequest getRequest() {
// something like this would be ideal:
if (!ServletContextFactory.isInServletContext()) {
// method was not called from ServletRequest, so there is none to be found
return null;
}
...