aspose file tools*
The moose likes Servlets and the fly likes request.getServerName behaviour Help Needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "request.getServerName behaviour Help Needed" Watch "request.getServerName behaviour Help Needed" New topic
Author

request.getServerName behaviour Help Needed

balasg jothi
Greenhorn

Joined: Sep 06, 2004
Posts: 6
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 ?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Couldn't get you.

What are you really trying to know?
What are you getting from those methods?
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

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


What do you mean by environment ?


Groovy
balasg jothi
Greenhorn

Joined: Sep 06, 2004
Posts: 6
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
Byron Estes
Ranch Hand

Joined: Feb 21, 2002
Posts: 313
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!


Byron Estes<br />Sun Certified Enterprise Architect<br />Senior Consulant<br />Blackwell Consulting Services<br />Chicago, IL<br /><a href="http://www.bcsinc.com" target="_blank" rel="nofollow">www.bcsinc.com</a>
balasg jothi
Greenhorn

Joined: Sep 06, 2004
Posts: 6
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: request.getServerName behaviour Help Needed