I'm working on servlet page that renders content based on geo-location
, and I want to use both sendRedirect
and forward
together; e.g; you browse example.com/aPage.jsp
from France
; first I want the servlet to redirect you to example.com/fr/aPage.jsp
and then forward you to the resources
page.
This is what I have in my servlet:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
....
response.sendRedirect(REDIRECT_URL_BASED_ON_GEO);
// after redirect forward the resources page
RequestDispatcher view = request.getRequestDispatcher(RESOURCES_PAGE);
view.forward(request, response);
...
}
But I get:
java.lang.IllegalStateException: Cannot forward after response has been committed
I know the error appears because I can't use both sendRedirect
and forward
one after another, but I don't know how to achieve what I want (as described above) without this.
any help?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…