Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Help needed for JSTL

 
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please clear my doubts



is giving output "Not Hello".Please clarify why is it happening.why not it is giving hello1?
 
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
x is a scripting variable. The JSTL and EL work with scoped variables.

Scriptlets and the JSTL/EL are not meant to work together, and should not ever be used together.
 
Gautam Bhalla
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:x is a scripting variable. The JSTL and EL work with scoped variables.

Scriptlets and the JSTL/EL are not meant to work together, and should not ever be used together.





Above is the code of generated servlet of my jsp page of which my previous post was content.
Here dots signify the implicit generated code by JASPER.The thing I want to convey is that can't x be accessed directly inside my jstl generated code in my servlet as per basic OOP concepts.
Got your point about JSTL/EL but still confused about scriptlets and JSTL.Please clarify
 
Bear Bibeault
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scriptlets are obsolete. As of JSP 2 (12 years ago!), the JSTL and EL are meant to replace scriptlets; not work with scriptlets.

Don't use scriptlets. Ever.

Gautam Bhalla wrote:The thing I want to convey is that can't x be accessed directly inside my jstl generated code in my servlet as per basic OOP concepts.



No. And it has nothing at all to do with OOP concepts. Variables within the EL and JSTL are not looked for anywhere but in the scopes.
 
Gautam Bhalla
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear,
:thumbup: :thumbup: :thumbup:

I respect you expert opinion ,But anyways (despite having some obsolete stuff),Still jasper is dealing with the same and making appropriate conversions into servlet class,That has to be executed as per expectations.I request you to slightly more justify your opinion.

May be possible I missing something and please correct me if so.
 
Bear Bibeault
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gautam Bhalla wrote:I request you to slightly more justify your opinion.


It is not an opinion, it is a fact. The EL will not look for variables in the Java code. It doesn't matter if the scripting variables are in-scope within the generated blocks of the servlet or not.

The EL is interpreted -- it's not just code plopped into the middle of the Java code of the implementation servlet like scriptlets. And if a referenced variable is not in one of the scopes (page, request, session or application) it will not be found. It's as simple as that.
 
Gautam Bhalla
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!! :jumpingjoy:javascript:emoticon(':beerchug:');
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
${x} gets interpreted approximately as pageContext.findAttribute("x")

This would not find you scriptlet variable "x" on the page.

however this value would be referenced by ${x}:
<%
request.setAttribute("x", Integer.valueOf(5));
%>

A very commonly used technique is for servlets to use code similar to this to set an attribute in scope and then forward to a jsp page, referencing the attribute via EL in the jsp.


 
Bear Bibeault
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But be aware that that is for learning purposes only. Never put scriptlet code in a JSP page; especially one where you are using the JSTL and EL.
 
Gautam Bhalla
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks Bear and Stefans,

:thumbup: :thumbup: :thumbup: :thumbup:

Thanks a lot for helping me to understand the concept more precisely.I would take care for the same in future.
 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic