I am actually instantiating a class within scriptlet. I am passing a value of a variable to that class's constructor in order to get it instantiated with those values. The variable is declared in jstl tag and the class instantiation is happening within scriptlet.
Understanding how things work never hurts in my opinion.
The JSTL variable space is the attributes in page, request, session and application scopes.
so if you had <c:set var="meaningOfLife" value="42"/>, that sets the pageContext attribute "meningOfLife" to the string "42". You could get it in scriptlet code as pageContext.getAttribute("meaningOfLife")
Having said that, I am fully in agreement with the other posters that JSTL and scriptlet code don't mix. The class should either be instantiated in a servlet, and set into an request attribute before you forward to a jsp, or some other method of population considered.
Does it really need to be in the constructor?
You could then have the following
Ok its a hack of a workaround, but it avoids use of scriptlets. It just means you use the parameterless constructor, and then call a setter method, as opposed to passing the value in a constructor.
Thanks for all your help. I am very very new to JSTL environment. So I will give you sample code.
In the above code, for the value of <VALUE OF PART NUMBER>, I can either take it from request object. If the request object doesnt contain value we have to take it from variable(jstl variable using c:set) defined in that jsp.
I want to know how I can perform the above task using JSTL tags?
[BPSouther: Added UBB Code Tags] [ December 07, 2006: Message edited by: Ben Souther ]
JSTL was not meant to be a fully functional programming language to replace scriptlets.
The intent was to give a JSP developer enough tools to work data structures (passed to the JSP via scoped variables) to be able to format and mark up the data as HTML without needing to resort to scriptlets.
When writing scriptless JSPs, you will want to employ MVC techniques to insure that all the heavy lifting is factored out of your JSPs into Servlets, Beans, and Plain Old Java Objects (POJOs) before context is passed to the JSP.
In my humble opinion, the only thing worse than a JSP with scriptets in it is a page with both scriptlets AND JSTL/EL code.
The code cannot be converted as-is because it contains calls to methods that require parameters. This is not compatible with the EL.
Using JSP 2.0 and JSTL/EL requires a slightly different way of thinking about the data that is sent to a page. Rather than sending whatever random structure you have available and trying to contort the page code (as you are trying to do) to adapt to it, your controller should do all the hard work and create data structures to send to the page that are easy for the page to handle with straight-forward JSTL and EL.
This article discusses this concept. [ December 07, 2006: Message edited by: Bear Bibeault ]
Please tell me how to implement the above code only using jstl and not using scriptlets within jsp. As using scriptlets and jstl within a jsp is not a good practice.
I think you missed my earlier point. JSTL is not a general purpose language and is not capable of replacing what you've got in your scriptlets. To implement a proper scriptless page, you will need to factor that scriptlet code out of your JSP altogether.