Solved

Servlet getRemoteUser

Posted on 2004-08-25
3
475 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

728 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