File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Not Getting client information from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Not Getting client information from a servlet" Watch "Not Getting client information from a servlet" New topic

Not Getting client information from a servlet

Ricardo Alvarado

Joined: Feb 23, 2004
Posts: 19
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 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();
if (req.getHeader("REMOTE_HOST") != null) {
REMOTE_HOST = req.getHeader("REMOTE_HOST").toString();

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

Scott Dunbar
Ranch Hand

Joined: Sep 23, 2004
Posts: 245
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()

<a href="" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Not Getting client information from a servlet
jQuery in Action, 3rd edition