Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Is it always used within JSP pages</p> </blockquote> <p>Yes.</p> <blockquote> <p>... and is it used only for getting data from the database.</p> </blockquote> <p>No. In fact, in mast cases it is BAD PRACTICE to access the database from a JSP, using JSTL or using other means (e.g. scriptlets).</p> <blockquote> <p>does it mean like most JSP would have an associated Java file like 1-1 mapped, where the logic to get data using SQL query is written and is given to the JSP page.</p> </blockquote> <p>Sort of. But there is not necessarily a 1 to 1 mapping:</p> <ul> <li>Not all JSPs need to access the database.</li> <li>A Java servlet may use multiple JSPs to render different output pages.</li> <li>Different servlets may share a single JSP; e.g. to render a common error message page.</li> </ul> <blockquote> <p>if yes, what exactly is the role of JSTL code within the JSP.</p> </blockquote> <p>The aim of a JSP is to render output; typically HTML pages, but it could be anything text-based. JSTL is used within JSPs when the the output rendering logic is too complicated or messy to express using JSP EL. </p> <hr> <p><strong>UPDATE</strong></p> <p>The old-fashioned alternative to JSTL and JSP EL is to embed Java code ... i.e. scriptlets ... in the JSPs. For example:</p> <pre><code>&lt;c:if test="${a == 'true'}"&gt; hi &lt;/c:if&gt; </code></pre> <p>is equivalent to something like this:</p> <pre><code>&lt;% if ("true".equals(context.findAttribute("a")) { %&gt; hi &lt;% } %&gt; </code></pre> <blockquote> <p>Also for JSTL use, from what i understand it is used within the JSP for dynamic HTML rendering through if..else statements.</p> </blockquote> <p>You are describing HTML whose structure and content <em>depends</em> request parameters, configuration parameters, data fetched from the database and so in. This is the primary uses of JSTL.</p> <p>However, this is NOT what is normally referred to as "Dynamic HTML". Dynamic HTML is where <em>the browser</em> changes the HTML of the currently displayed page; e.g. when Javascript embedded in the page changes displayed page by modifying the DOM. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload