• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

request.getServerName behaviour Help Needed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using request.getServerName() in the code to get the servername and request.getServerPort() to get the port no.

What happened means,depends upon the environments the code returns
servername and port no from getServerName() call.

why this happened ? In what scenarios request.getServerName behaves like that ?
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Couldn't get you.

What are you really trying to know?
What are you getting from those methods?
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What happened means,depends upon the environments the code returns
servername and port no from getServerName() call.



What do you mean by environment ?
 
balasg jothi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ansari,

I am trying to get the ServerName from URL requested from Browser.

Its returning value servername and port no For example:
ssunncc.asp.com:9081

According to the Sun API the value only upto ssunncc.asp.com.Then why returning with port also.

Its making trouble to my code,because I am doing some comparing the servername and port no receiving from browser with same value in xml config.


Thanks
Bala L
 
Ranch Hand
Posts: 313
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure why it would be doing that. You're absolutely right in saying the API indictates that the getServerName call should return the IP address or DNS name up to, but not including the colon (":") and port number.

So now you know you can't trust it to return only that part of the value. You can't control that aspect of your environment, but you can control how you perform the compare against the value in your xml file.

I'd probably use the String.indexOf fuction to see if it contained a colon (...after I checked to see if was null to avoid a nasty null pointer exception in the unlikely event that it was null).

If a value greater than -1 comes back (integer), then it contains a colon so it must have the port appended to it. Using that index, I would substring the servername from the beginning of the string to that index and use that for my comparison.

Ideally you wouldn't need to do this, but real life and applications are rarely ideal.

Good Luck!
 
balasg jothi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Byron.

Thanks.But really a hectic.

Can you ask Sun about this ISSUE,Beacuse you are already Sun Architect.

otherwise we will raise the new JSR for this .

Thanks
Bala
 
reply
    Bookmark Topic Watch Topic
  • New Topic