• 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

Not Getting client information from a servlet

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to get clients info from a client... I tested on a jsp and it works fine but it seems that it's not working with my servlet...

This is my code

String HTTP_USER_AGENT ="";
String REMOTE_HOST = "";
String REMOTE_ADDR= "";
String REMOTE_USER= "";
String SERVER= "";
String SERVER_PORT= "";

if (req.getHeader("HTTP_USER_AGENT") != null) {
HTTP_USER_AGENT = req.getHeader("HTTP_USER_AGENT").toString();
req.getSession().setAttribute("HTTP_USER_AGENT",HTTP_USER_AGENT);
}
if (req.getHeader("REMOTE_HOST") != null) {
REMOTE_HOST = req.getHeader("REMOTE_HOST").toString();
req.getSession().setAttribute("REMOTE_HOST",REMOTE_HOST);
}
....



There is nothing really special in this servlet, all I need is client info. Do someone nows what could this be happening ....

Thanks
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd encourage you to take a look at the docs for ServletRequest. In there are many of the methods you want. Additionally, you need to take a look at the HTTP RFC to see the standard HTTP header names. For example, the (optional) user agent is specified as "User-Agent". Are you converting this from a CGI script? That is what your variables look like.

To be clear:

HTTP_USER_AGENT --> request.getHeader( "User-Agent" )
REMOTE_HOST --> request.getRemoteHost()
REMOTE_ADDR --> request.getRemoteAddr()
REMOTE_USER --> request.getRemoteUser()
SERVER --> request.getServerName()
SERVER_PORT --> request.getServerPort()
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic