Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not Getting client information from a servlet

 
Ricardo Alvarado
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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
 
Scott Dunbar
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • 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()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic