栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring Boot:从网址中删除jsessionid

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Boot:从网址中删除jsessionid

我创建了一个快速且肮脏的spring-boot应用程序,这就是我想到的。

生成的ServletInitializer可以按以下方式更改:

package com.division6.bootr;import java.util.Collections;import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.SessioncookieConfig;import javax.servlet.SessionTrackingMode;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.context.web.SpringBootServletInitializer;public class ServletInitializer extends SpringBootServletInitializer {    @Override    public void onStartup(ServletContext servletContext) throws ServletException {        // This can be done here or as the last step in the method        // Doing it in this order will initialize the Spring        // framework first, doing it as last step will initialize        // the Spring framework after the Servlet configuration is         // established        super.onStartup(servletContext);        // This will set to use cookie only        servletContext .setSessionTrackingModes(     Collections.singleton(SessionTrackingMode.cookie)        );        // This will prevent any JS on the page from accessing the        // cookie - it will only be used/accessed by the HTTP transport        // mechanism in use        SessioncookieConfig sessioncookieConfig=     servletContext.getSessioncookieConfig();        sessioncookieConfig.setHttponly(true);    }    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {        return application.sources(SpringBootrApplication.class);    }}

作者注

我不确定该何时引入,但是通过引入以下参数,无需编写代码即可实现相同的目的:

  • server.servlet.session.cookie.http-only = true
  • server.servlet.session.tracking-modes = cookie


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/395487.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号