• Post Reply Bookmark Topic Watch Topic
  • New Topic

Domain name from request

 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose i access a resource over the web....

like say...
http://www-128.ibm.com/developerworks/websphere/library/tutorials/0702_patil/0702_patil.html


I want to create the domain name from the request as below

<a href="http://www.ibm.com</b rel="nofollow">" target="_blank">http://www.ibm.com[/b]

is there any defined methods in servlet api..to do so??
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked?
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried it in on my machine ..

but the server name is localhost.... I dont have a domain ...


To get the domain name ...i tried it this way...

request.getScheme()+"://www."+request.getServerName()+":"+request.getServerPort()


or

request.getScheme()+"://www."+req.getLocalName()

but how to change to retain or change the www-128 part of the request??
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this should work...but cant test it over a .com domain

String durl=
req.getRequestURL().substring(
0,req.getRequestURL().indexOf(req.getRequestURI()));

Regards
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are trying to get the domain name from the url then you might do some string manupulation as mentioned in some of the other posts before.

Another way would be to query the request for header named Host.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the problem because at local machines it would give you only


localhost or localhost:8080

there was no .com or www-128 in the output whih i had wanted

but there is no domain asscociated with my machine...

So i wanted to know whether there was any pre defined method that could address my problem.

But i think that the last post which i wrote would be sufficient for this..

Thanks ...

Regards
[ March 29, 2007: Message edited by: A Kumar ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!