Solved

Servlet getRemoteUser

Posted on 2004-08-25
3
458 Views
Last Modified: 2013-11-24
Currently i have been using this technique where when a user logs into my site which is through a servlet, i call request.getRemoteUser() which returns a string of their ip address.  I then use that IP address to do a lookup in my user table to see when this ip address last logged on and as which user, so that i can set the user to that previous choice. I didnt want to use a cookie.  Anyhow, the problem has started where i have two users behind the same firewall. Both users are showing up with the same IP which looking back on it, now is what i would expect. Is there "any" other value of something i could extract that would give me something unique about that user that i could work with in this situation to tell who they are?

Thanks!
0
Comment
Question by:Hokester
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11896992
No ;-)
0
 
LVL 92

Expert Comment

by:objects
ID: 11897931
Not really, and there are other conditions where this will also occur.
Why don't you want to use cookies, again not guaranteed but will improve your coverage.
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 125 total points
ID: 11898130
The J2EE specification already has this functionality built into the Servlet API.  The request.getSession(TRUE) will create the session object automatically.  If cookies are enabled the sessionID will be stored as a cookie on the client.  If the client has cookies turned off, the servlet will use URL rewriting.  

If you can't or do not want to use the Servlet API (for example you don't want to create cookies), then you could implement the session functionality using URL rewriting.   Your servlet code would be something like this:

String sessionID=request.getParameter("UserSessionID");
if (sessionID==null) { //User is using a new session
   response.setRedirect(AppUserSession.encodeURL("/MyApp/loginPage.jsp");
}
else
{
  AppUserSession UserSession=AppUserSession.findUserSession(sessionID);
  //Process logged in user's request
}

The class AppUserSession would look something like this:
public class AppUserSession
{
    /**
      * Rewrite the url to contian the session ID as a parameter
      */
    public static String encodeURL(String url)
    {
         String userID=...// Some code to generate Unique ID (i.e. hash of the user's IP address plus system clock time)
         SessionMap.put(userID, new HashMap());  //Probably should be readonly Map instead
         return url + (url.indexOf("?")>-1 ? "?" : "&")+"UserSessionID="+userID;
    }

   public static Map findUserSession(String sessionID)
   {
      return sessionMap.get(sessionID);
   }
    //...Other functions as necessary
}
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Exchange and Third Party application. 8 60
scoresSpecial  challenge 13 42
for i loop in grovy 1 32
groovy example issue 10 70
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now