0
我想知道什么是获得HttpServletRequest对象在DWR和Spring应用程序的正确方法 - 我尝试做如下:获得的HttpServletRequest在DWR和Spring应用程序
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它会告诉,这样我就可以直接返回空值:
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;
}
...