• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get current page's URL with "doPost" method ?

 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

<base href="http://server/servlet/MyServlet?"<%= request.getQueryString() %>">

but it doesn't work. what can I do to pull the <base> back to current page so that anchor for sections will work ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why aren't you using relative URLs?
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Wolf
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Artemesia,

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: -



This will give you "/" in your case.

 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
he URL is always "http://server/servlet/MyServlet"

Your use of /servlet/ indicates that you may be getting tangled up in problems related to the "invoker" servlet. See this FAQ on the invoke here at the ranch.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic