zoukankan      html  css  js  c++  java
  • Spring boot 去除URL 里的 JSESSIONID

    方法一 application.yml 里设置

    server:
      port: 80
      servlet:
        session:
          tracking-modes: cookie
          cookie:
            http-only: true
    

    方法二 启动类继承SpringBootServletInitializer 类,重写 onStartup 方法

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
    import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
    
    
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.SessionCookieConfig;
    import javax.servlet.SessionTrackingMode;
    import java.util.Collections;
    
    @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
    public class NdaDemoApplication extends SpringBootServletInitializer {
    
        public static void main(String[] args) {
            SpringApplication.run(NdaDemoApplication.class, args);
        }
        public void onStartup(ServletContext servletContext)throws ServletException {
            super.onStartup(servletContext);
            servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
            SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();
            sessionCookieConfig.setHttpOnly(true);
        }
    }
    
  • 相关阅读:
    28335外部中断的简单介绍和配置
    C++中强制类型转换
    GitHub上Markdown语法的高级应用
    C++中强制类型转换
    模拟鼠标点击事件
    clone一行div tr 每次增量赋值
    linux tomcat自动部署shell
    maven 引用本地jar
    JDK自带工具keytool生成ssl证书
    jenkins+maven+svn实现简单的一键发布
  • 原文地址:https://www.cnblogs.com/lick468/p/11108709.html
Copyright © 2011-2022 走看看