spring拦截器里如何获取request
自己写的拦截器继承MethodInterceptor,invoke(MethodInvocation args)方法中如何获取request?
Object[] argObjects = args.getArguments();
for (int i = 0; i < argObjects.length; i++) {
if (argObjects[i] instanceof HttpServletRequest)
request = (HttpServletRequest) argObjects[i];
}
这样写获取不到
测试了下,args.getArguments()里只有1个对象,用toString方法显示为“{}”,是什么意思?
------解决方案--------------------你这是Spring的方法吗?我看起来像是Struts的。
------解决方案-------------------- /**
* 得到request请求
*
* @param invocation
* @return request请求
*/
protected HttpServletRequest getRequest(ActionInvocation invocation) {
return (HttpServletRequest) invocation.getInvocationContext().get(
StrutsStatics.HTTP_REQUEST);
}