Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Can';无法从Spring获取附带凭据的HttpServletRequest_Java_Spring_Servlets_Httprequest - Fatal编程技术网

Java Can';无法从Spring获取附带凭据的HttpServletRequest

Java Can';无法从Spring获取附带凭据的HttpServletRequest,java,spring,servlets,httprequest,Java,Spring,Servlets,Httprequest,我试图在web应用程序中从Spring获取请求对象,但是无论我采用何种方法,用户名(/credentials)部分总是缺少 我使用了@Autowired和 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); 接近,但请求似乎已被Spring删除了所有凭据信息 我怎么把这些拿回来?我需要一个完整的请求对

我试图在web应用程序中从Spring获取请求对象,但是无论我采用何种方法,用户名(/credentials)部分总是缺少

我使用了@Autowired和

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删除有用的位之前,我如何回到原始请求?谢谢,我想到了另一种方法——无论如何,谢谢。