• Post Reply Bookmark Topic Watch Topic
  • New Topic

accessing request implicit object in JSP  RSS feed

 
Ken Sampson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I understand that I need to access the request attribute object in a jsp using the following:

<% request.getAttribute("username")%>

assuming there exists an attribute as username.

But here I am using scriplets which should be avoided. I would like to try the same thing using EL. Using the implicit pageContext object I may be able to do the following:

${pageContext.request.method} to get GET or POST as the method.

But how can I access an attribute and perform the above operation. I tried to do this:

${pageContext.request.attribute} but this won't work. Is there any workaround for this or I need to do this always using Scriplets.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In EL there is also an implicit object called requestScope : ${requestScope.username}. If the username is only in the request scope, you can even get it via ${username}. In this case, the container will look in all scopes (page,request, session, and application scopes) for the attribute and return it when found.
 
Ken Sampson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all so much!!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!