Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting attribute using EL

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

can this be done using EL:

<% request.setAttribute("username");%>
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can this be done using EL:

No. EL is used to read values, not to set values. Remember that a JSP is usually used as a view, so all you should do is read data.
 
Marimuthu Madasamy
Ranch Hand
Posts: 72
Java Monad Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i hope you mean
<% request.setAttribute("username", "user123"); %>

You can do this using JSTL EL,


or
if userName is a request parameter.


but as Christophe said, try to avoid setting variables in request, session, application scopes inside JSP (instead use controller). If you want to create temporary variables inside jsp, create those in "page" scope (in c:set, simply dont mention "scope" attribute).
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do this using JSTL EL

c:set is a JSTL tag, not something from the Expression Language ;)
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic