我需要以下服務器端重定向或在Tomcat服務器上轉發:url http://portal.customer_name需要重命名/重定向到http://portal.customer_name/customer_name。簡而言之,沒有上下文路徑的url將被重定向到具有上下文路徑的相同url。 我設法用過濾器做到這一點,使用request.getRequestDispatcher()。forward(request,response);但同樣的東西似乎並不適用於閥門。tomcat正向閥
我走到這一步,下面:
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;
}
我部署了一些小服務程序,這似乎收到原始地址而不是重定向。有沒有可能像這樣做一個服務器端重定向。請注意,我需要一個閥門,而不是過濾器。
我發現博客帖子,而是因爲它創造了客戶方的重定向和我需要服務器端重定向無法使用的代碼。我沒有意識到我可以檢查出jBoss的實現,謝謝。 – Berend
更新了我的答案。 –
我意識到'正確'的短語應該是'轉發'的請求,我不得不使用getrequestDispatcher.forward()爲我的閥門以我想要的方式工作,更新我的問題。 – Berend