Sending redirect in Tomcat web application behind a Apache 2 proxy (mod_proxy)

前端 未结 5 695
攒了一身酷
攒了一身酷 2021-01-01 18:20

I have a web application on tomcat http://localhost:8080/WebApp/

The I have configrued Apache 2 (mod_proy) so that the web application is directly acces

5条回答
  •  失恋的感觉
    2021-01-01 19:08

    Use forwarding instead of redirection

    I think your problem is the use of sendRedirect. Calling sendRedirect is actually suppose to show the browser that the URL has been redirected. If you want to hide that you need to use forwarding.In your servlet try this instead of sendRedirect.

    String servletPath = request.getServletPath();
    if(servletPath.equals("/app1")){
         ServletContext ctx = request.getServletContext().getContext("/app1");
         RequestDispatcher dispatcher=ctx.getServletContext().getRequestDispatcher( "/app1/app1.html" ); // or wherever you actually keep app1.html
         dispatcher.forward( request, response );
    } 
    

    Inside your context.xml set crossContext = "true" so you can forward requests to other web applications.

    
    

提交回复
热议问题