Java Can';无法从Spring获取附带凭据的HttpServletRequest
我试图在web应用程序中从Spring获取请求对象,但是无论我采用何种方法,用户名(/credentials)部分总是缺少 我使用了@Autowired和Java Can';无法从Spring获取附带凭据的HttpServletRequest,java,spring,servlets,httprequest,Java,Spring,Servlets,Httprequest,我试图在web应用程序中从Spring获取请求对象,但是无论我采用何种方法,用户名(/credentials)部分总是缺少 我使用了@Autowired和 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); 接近,但请求似乎已被Spring删除了所有凭据信息 我怎么把这些拿回来?我需要一个完整的请求对
HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
接近,但请求似乎已被Spring删除了所有凭据信息
我怎么把这些拿回来?我需要一个完整的请求对象来创建另一个库所需的凭据对象
谢谢您可以将
HttpServletRequest
注入控制器。
如果需要获取用户名,还可以插入java.security.Principal
例如:
@RequestMapping(value = "/path", method = RequestMethod.POST)
public String path(Principal principal, HttpServletRequest request) {
// do ur thing
// return username
principal.getName();
return "path";
}
您使用的是哪个版本的spring?3.1.1.3.1.0.RELEASEHi,我需要一个请求对象来实例化Modeshape ServletCredentials(req),但是由于spring删除了所有凭据数据,ServletCredentials实例基本上是无用的。在Spring删除有用的位之前,我如何回到原始请求?谢谢,我想到了另一种方法——无论如何,谢谢。