wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Not Getting client information from a servlet" Watch "Not Getting client information from a servlet" New topic
Author

Not Getting client information from a servlet

Ricardo Alvarado
Greenhorn

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 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

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="http://forums.hotjoe.com/forums/list.page" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not Getting client information from a servlet
 
Similar Threads
Retaining value of checkbox when returning back from a servlet
Regarding retrieving of session information
Constructor Problem
Mock exam doubt from - Head First..
HttpSessionBindingListener Q