• Post Reply Bookmark Topic Watch Topic
  • New Topic

'callback' url

 
William Stafford
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to send a url to my servlet to another server that will use the url to place a 'callback' link to my servlet on their page.

My servlet does a search and presents a small map created by a mapper on another server. My page also has a link that takes the user to that other server and displays a larger version of the map. I need to pass a URL that will take the user back to my search servlet. The mapper adds some new params to the URL so this is more than back button functionality.

I've looked at the many methods in HttpRequest and HttpServletRequest and I can see several ways of building the URL but I was wondering what the preferred way is.

I only need the portion of the URL up to the servlet name.
For urls such as http://localhost:80/someContext/servlet?blah blah blah
or http://my.domain/someOtherContext/servlet?blah blah blah
I need the portion starting at or after 'http//' and ending at 'servlet'

I'm sure this is pretty basic so I apologize in advance, just give me the URL m'am.

-=beeky
 
Vijay K Vivek
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the getRequestURI() method on the HttpServletRequest object.

request.getRequestURI() should strip off the query string and provide the url from the protocol upto query string.
 
William Stafford
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijay,
Thanks for the reply! Your suggestion was not quite what I needed but it lead me to the solution.

In case someone comes across this post via a search I'll describe how to do what I asked about.

Basically all you need to to is use HttpServletRequest.getRequestURL(). This method returns a StringBuffer containing everything in the original URL up to but not including the query string.

In my case I needed to add a different query string but that was easy.

-=beeky
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!