Java 如何获取在context.xml上配置的会话cookie的自定义名称
我有一个REST服务接收HttpServletRequest,我需要加载此对象的会话cookie。如果没有更改,我可以按名称JSESSIONID加载,但是可以在context.xml中更改该名称,就像在示例中一样Java 如何获取在context.xml上配置的会话cookie的自定义名称,java,spring,catalina,Java,Spring,Catalina,我有一个REST服务接收HttpServletRequest,我需要加载此对象的会话cookie。如果没有更改,我可以按名称JSESSIONID加载,但是可以在context.xml中更改该名称,就像在示例中一样 <Context sessionCookieName="CUSTOMSESSIONID"> <!-- Default set of monitored resources. If one of these changes, the
<Context sessionCookieName="CUSTOMSESSIONID">
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
</Context>
WEB-INF/WEB.xml
${catalina.base}/conf/web.xml
公共列表收集cookies(HttpServletRequest){
if(request.getCookies()!=null){
final List cookiesList=Arrays.asList(request.getCookies());
返回cookiesList.stream()
.过滤器(
饼干->
“JSESSIONID”.equals(cookie.getName())
||“ApplicationGatewayAffinity”.equals(cookie.getName()))
.collect(Collectors.toList());
}
返回新的ArrayList();
}
为了知道会话cookie使用的名称,我可以/应该使用什么服务
谢谢你的帮助
public List<Cookie> collectCookies(HttpServletRequest request) {
if (request.getCookies() != null) {
final List<Cookie> cookiesList = Arrays.asList(request.getCookies());
return cookiesList.stream()
.filter(
cookie ->
"JSESSIONID".equals(cookie.getName())
|| "ApplicationGatewayAffinity".equals(cookie.getName()))
.collect(Collectors.toList());
}
return new ArrayList<>();
}