• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help needed for JSTL  RSS feed

 
Gautam Bhalla
Ranch Hand
Posts: 30
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!! :jumpingjoy:javascript:emoticon(':beerchug:');
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!