zoukankan      html  css  js  c++  java
  • 解决spring boot项目中链接多出jsessionid的问题

    在HTML中用<input id="urlcontext" type="hidden" th:value="@{/}" /> 时会发现得到的链接会是  " /项目名/;jsessionid=xxxxxxxxxxxxxxxxxxxx"  这样的形式,这样再去拼接链接访问就会报错。

      在启动类上继承   SpringBootServletInitializer  类,然后重写  onStartup  方法:

    public void onStartup(ServletContext servletContext) throws ServletException{
            super.onStartup(servletContext);
            servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
            SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();
            sessionCookieConfig.setHttpOnly(true);
    }

      这样就可以解决URL中出现的jsessionid的问题。

      

      然后有个问题是

      我在spring boot 2.0.0 RELEASE版本中使用内嵌Tomcat启动时,在application.yml中增加如下:

    server: 
      session: 
        tracking-modes: cookie

     发现不生效,org.springframework.boot.autoconfigure.web.ServerProperties 这个类也没有trackingModes这个属性。如果有人知道原因,望能在评论中告知,不胜感激。

    如有错误,欢迎大家指正,共同进步。
  • 相关阅读:
    Algs4-2.1.23纸牌排序
    python字符串加颜色区别
    python学习之字典
    python学习之while语句
    python学习之字符串变量
    python学习之列表语法
    python简单实现用户表单登录
    python学习之安装模块
    python学习之认识字符串
    python学习之for语句
  • 原文地址:https://www.cnblogs.com/deng720/p/8601196.html
Copyright © 2011-2022 走看看