Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
A new Cookie is added instead of replacing existing one

I just finished localizing my web application using spring boot configuration as a base.

@Bean
public LocaleResolver localeResolver() {
    return new CookieLocaleResolver();
}

Due to a requirement one is supposed to be able to change locale/language of the website by pressing a button. Said function is implemented with a little bit of JS and a cookie.

<script>
    function updateCookie(lang) {
        let name = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE"
        document.cookie = name+"="+lang
        location.reload()
    }
</script>

<a onclick="updateCookie('de')" class="flag-icon flag-icon-de mr-2"></a>

The idea is to update said cookie on click of a button and use it throughout the whole application. This works fine until I am trying to call a specific endpoint in my application.

In order to debug my application I use:

window.onload = function () {
        alert(document.cookie)
}

Now to my problem:

When User-Testing the application this is the alert-feedback:

org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE=de

Switching to other pages, refreshing, changing language etc. properly resets the cookie with a different value.

When calling a specific endpoint though, I get the following alert:

org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE=de;
org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE=fr

Instead of resetting/changing the existing cookie, a new one is added with the value 'de;'. A seemingly random semicolon is added.

This doesn't happen with endpoints using similar logic and almost identical implementation. There is no further logic outside the little bit of JS code I've posted and I'm not touching the cookie in the backend.

Unfortunately I'm out of ideas. Any tips/help would be appreciated.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda