Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to retrieve server path from request  RSS feed

 
Pinal N Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

How can I retrieve entire server path from the request object?

For eg: Say I am accessing an application with URL http://www.temp.com/HelloWorld/index.jsp. Through HttpServletRequest object, How can I retrieve "http://www.temp.com/HelloWorld".

I tried with request.getServerPath and getConextPath, both methods do not return "http://www.temp.com".

Any help would be appreciated in advance!!

Thanks,
Pinal
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are more than just those methods available. Write a test application to call all the various methods and see what they return. That way you will learn which ones to use when you need that piece of information.
 
Maryam Nouhnejad
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just in case you didn't found any method, then you can set the server path in the <init-param> tag of web.xml and then use ServletConfig to access the url.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maryam Nouhnejad:
Just in case you didn't found any method, then you can set the server path in the <init-param> tag of web.xml and then use ServletConfig to access the url.


Why on earth would he do that when the data is available dynamically from the request?
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As suggested, you can write a test app to see what all the methods return. I believe this is the one you need though.

request.getServerName()
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!