Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accesing request.getRemoteUser() using EL expressions

 
Krzysiek Hycnar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Is there an elegant way to access information about username and possibly roles assigned to him using EL expressions??

In my JSPs I use conditionals to display different page contents to different users. The best solution to me would be something like this...

<c:choose>
<c:when test="${sessionScope.remoteUser==null}">
page content for user that has not logged in yet...
</c:when>
<c therwise>
Hello <c ut value="${sessionScope.remoteUser}"/> etc...
</c therwise>
</c:choose>

However the problem is that there is no sessionScope.remoteUser after the user has logged in (I know requestScope.remoteUser looks like it might work but it does not).

To make the above JSP work, a following scriptlet must be added before the JSTL conditionals:

<%
String user = request.getRemoteUser();
if(user!=null && request.getSession(false)!=null && session.getAttribute("remoteUser")==null)
session.setAttribute("remoteUser", user);

%>

How can I achieve my goal without that scriptlet??
Again the finnset solution would be if the code setting the remoteUser attribute ran only once, just after the user has successfuly loged in.

Is there a way to intercept the authentication procedure and smuggle some custom code there (for now I use form based authentication with JDBC Realm configured) ??

Thanx in advance for your suggestions.

Regards
Chris
 
Krzysiek Hycnar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> (I know requestScope.remoteUser looks like it might work but it does not).
Of course it's not supposed to work!! It's not a parameter neither an attribute <ashamed>
Chris
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably unnecessary: I guess you figured out ${request.remoteUser} then?

- Peter
 
rick zorich
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try ?
${pageContext.request.remoteUser}
 
Krzysiek Hycnar
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${pageContext.request.remoteUser} works!!
Thanx Rick
Chris

PS
Where can I read more about JSTL and EL expressions??
 
rick zorich
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got that out of "JSTL in Action" by Shawn Bayern.
But it only covers JSTL 1.0.
Does anybody have a book for JSTL 1.1 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I was learning JSTL, I kept a copy of this book handy. You can read about it in our JavaRanch Bunkhouse.

Once you understand how the EL interprets references, creating constructs like the above become quite second nature.
[ August 29, 2004: Message edited by: Bear Bibeault ]
 
rick zorich
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear, that book is a year old already.
What about JSTL 1.1 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you could always do what I do and go straight to the specification. There's nothing quite like a peek into the horse's mouth.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic