Java servlet具有重定向和转发方法。它们之间的区别在here上进行了说明,您可以按如下方式使用它们;重定向改变了url,但转发处理请求内部。
如果你想将用户重定向到一个远程URL检查this Q&A,也许在不改变浏览器的地址重定向,最简单的方法是用url阅读它并把它写进响应上的servlet
private void redirect(ResponsePage aDestinationPage, HttpServletResponse aResponse) throws IOException {
String urlWithSessionID = aResponse.encodeRedirectURL(aDestinationPage.toString());
aResponse.sendRedirect(urlWithSessionID);
}
private void forward(ResponsePage aResponsePage, HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException, IOException {
RequestDispatcher dispatcher = aRequest.getRequestDispatcher(aResponsePage.toString());
dispatcher.forward(aRequest, aResponse);
}
另外的用户名在url地址上,您可以使用filters并将其重定向为您的愿望。如需使用带滤波器的弹簧,请检查here和here
有没有特殊的弹簧方式来转发请求? –
我认为过滤器可以解决您的问题。有关使用弹簧与过滤器请检查http://learningviacode.blogspot.com.tr/2013/07/filters-and-spring.html和http://www.mkyong.com/spring-mvc/how-to-寄存器-A-servlet的过滤器在弹簧-MVC / –