how to get current page's URL with "doPost" method ?
Joined: Jun 21, 2005
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.
Joined: Feb 18, 2002
If you need a static variable, just create a new parameter called "current" and use requestDispatcher to forward it to the JSP.
In your JSP, use the following call: -
If you want to get the context than I would suggest using: -
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.
The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny GillTweets
Author and all-around good cowpoke
Joined: Mar 22, 2000
he URL is always "http://server/servlet/MyServlet"