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;
}
...