Approach 1 :
4 different servers, mean four different URLs ok.
suppose ur application url is
http(s)://ipaddress:port/application
now it is possible that all four server instances are on same machine. in that case "ipaddress" would be same. but port would be different. if machines are different in that case both ipaddress and port would be different.
now inside your code you can get absoultepath. absolutepath would consist of the complete URL of the file absolutepath is requested on. like
http://ipaddress:port/application/abc/def/x.java.
Now from this you can extract the port/ipaddress and write your logic.
Approach2:
have a property file inside your application that contains the server its being deployed on. ( right now I cant think of something to set this automatically, but while deployment you can set the server name in this property file)
later on when you need. you can read the property file and you will know which version of application you are running on.
personally I`d prefer approach2 (and should be prefered in case we can think of initializing the properties file automatically)
Hope it helps :-)