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

197
Visualizações
How to set www before domain name and after http:// in Spring Boot and JavaScript?

I want to know about redirection of domain. That is I want to add www before domain name. How to achieve this thing in Spring boot and JavaScript.

My URL is : https://example.com/dashboard

I want this: https://www.example.com/dashboard

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I think it should be configured in the frontend like apache or proxy (nginx or other).

about 4 years ago · Juan Pablo Isaza Relatório

0

I would advise to redirect at your web server configuration, outside the Spring Boot aplication. But in case you want to redirect for some specific reason you could add Filter to your Spring Boot Configuration:

@Component
public class RedirectionFilter extends GenericFilterBean {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {

        final String host = request.getServerName();
    
        if (!org.apache.commons.lang.StringUtils.startsWithIgnoreCase(host, "www.")) {
            HttpServletRequest httpRequest = (HttpServletRequest) request;
            HttpServletResponse httpResponse = (HttpServletResponse) response;
            
            //obtain the full requested URL
            StringBuffer requestURL = httpRequest.getRequestURL();
            String queryString = httpRequest.getQueryString();
            if (queryString != null) {
                requestURL.append("?").append(queryString);
            }
            
            //set up redirect
            String redirectURL = requestURL.toString();
            redirectURL = redirectURL.replace(host, "www." + host);
            httpResponse.sendRedirect(redirectURL);
        }  else {
            chain.doFilter(request, response);
        }
    }
}
about 4 years ago · Juan Pablo Isaza Relatório
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