wood burning stoves*
The moose likes Servlets and the fly likes Problems writing a login filter using getRemoteUser() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problems writing a login filter using getRemoteUser() method" Watch "Problems writing a login filter using getRemoteUser() method" New topic
Author

Problems writing a login filter using getRemoteUser() method

Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 153
I'm trying to write the following filter to get the user name and password after a user logs in, to store this as a session object and use the object to return user details. The problem is I can't seem to resolve the getRemoteUser method. I looked at the javax.servlet.http library and the method I need is right there, but it throws a 'cannot resolve symbol' error in the IDE (Netbeans). I always thought method classes loaded in the library can be resolved at compile time. Never seen this error before.

Why is it not possible to resolve the getRemoteUser method? Is incorrect to simply call this method using the HttpServletRequest request parameter like:

String remoteUser=request.getRemoteUser(); ?

Do I have to write a custom implementation of this method?

When I do this it fails to resolve even though I can see the getRemoteUser method in the HttpServletRequest class in my project library

Thank you!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Why are you casting the parameter and then ignoring the cast?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 153
Sorry I'm not aware of how I'm ignoring the cast. I thought that by casting the parameter to type HttpServletRequest means that the parameter 'request' can use HttpServletRequest in the subsequent method call?

So would it be more appropriate to change the parameters so that I can use 'use' the cast like so?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

Yes, this is basic Java. Servlets do not act any different than any other Java code. If you want to use the result of the cast, you must use the variable that recevies the casting.
Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 153
Thank you. Problem solved!
 
 
subject: Problems writing a login filter using getRemoteUser() method
 
Similar Threads
Question about servlet filters
Tomcat servlet-mapping bypass if real file requested
Filter Problem
problem while giving a url pattern in filter mapping
Session is not expired after specified time period