I need the following serverside redirect or forward on a Tomcat server: the url http://portal.customer_name needs to be renamed/redirected to http://portal.customer_name/customer_name. So in short, an url without context path to be redirected to the same url with context path. I managed to do this with a filter, using request.getRequestDispatcher().forward(request, response); but the same doesn't seem te work with a valve.
I got the following so far:
public void invoke(Request request, Response response) throws IOException, ServletException {
String context = getForwardpath(request);
request.getRequestDispatcher(context).forward(request, response);
this.getNext().invoke(request, response);
}
private String getForwardpath(Request rq){
String context = rq.getServletContext().getContextPath();
/.../
return context;
}
I deployed some servlets which seem to receive the original url but not the redirect. Is it possible to make a serverside redirect like this at all. Please note that I need a valve, not a filter.