• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using scriptlets and JSTL

 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Am facing a strange problem. i am checking for a session attribute in my jsp. When i use scriptlets it works fine but when i try to use JSTL it dosent seems to work out.

This gives me-: Not present with scriptlets

while when i use this-:

Gives me nothing

Any ideas???
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This should be in the JSP forum, since it's not Struts-related.

Why is only half of your expression in the JSTL expression?
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Firstly, you should use proper indention(opening bracket, closing brackets) which helps us to understand the problem code better.

Second, your syntax for EL in JSTL expression is wrong,

EL evaluates the attributes stored in session scope and print it, if it unable to find it in the scope, it simply return empty string, that's mean it prints nothing. So you can able to find out your problem now and Google about "How to check null objects using EL" for workaround.

HTH
 
Pranav Bhatt
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sagar/David,

Thanks for the showing me the correct way. Its fine now (added that empty operator ). Regarding code am sorry as i just wrote it like draft to check how it goes. Will keep that clear next time.

Thanks a lot again..
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Sagar: That's not correct: if there's a value in sessionScope then ${sessionScope.value == null} works fine. The OP's off-topic code doesn't work because the EL expression is terminated before the null check.
 
Pranav Bhatt
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David,

I tried to get output of sessionScope.user but it was giving me nothing. I guess it returns empty only if attribute is null.
As gave me nothing not even null... but checking with that empty operator worked out fine...
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just ${sessionScope} is meaningless; you'd need to specify an attribute.
 
Pranav Bhatt
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops Sorry I meant this:

This wont fetch any value is "user" is null. It results as Attribute is-: on browser
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:@Sagar: That's not correct: if there's a value in sessionScope then ${sessionScope.value == null} works fine. The OP's off-topic code doesn't work because the EL expression is terminated before the null check.


hmm, after giving some deep thought, I found some points to share.
  • ${sessionScope.value}, returns an empty string "", if 'user' is not in session scope.
  • ${sessionScope.value == null}, returns an Boolean value
  • c:if test=${sessionScope.value} == null, This is something interesting, because "test" attribute takes only EL expression which results into a 'boolean' value OR 'true'/'false' string value. So in this example, if this string is considered as EL expression, then we know that its not an EL and failed to evaluate and returns false(I assumed this because of the behavior, I don't know the actual implementation). So what David says, " EL expression is terminated before the null check." is related to this(Just correct me here).
  •  
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic