Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda