I have a servlet which forwards to a JSP page. In the JSP page, I need to change <base href=".."> for few times because on my page there are links to other server domains. Meanwhile, in the page I create some anchors for sections in the page. Thus, if the anchor click needs to work, it needs to turn the href back to the current page's URL. However, the URL is always "http://server/servlet/MyServlet" because it uses POST method. I tried
Originally posted by Ben Souther: Why aren't you using relative URLs?
For the anchor link I did use relative link. The problem is I need to turn the "base" into current page so that the relative link will work. And that's why I want to kow how I can do that using "request" related API.
I am not sure I understand your problem completely. But if the problem is that you are using a RequestDispatcher to forward the reponse to a JSP, and hence the url in address bar is still pointing to the original servlet, you can try using HttpServletResponse.sendRedirect() method instead.