Saturday, July 18, 2009

Referencing a Text JSP Custom Tag Defined in Another Page

You could define the contents of a Text tag in a page

RunFirst.jsp

<h2g2j:text id="sesquery" scope="session">
SELECT NAME, ADDRESS, JOBID
FROM EMPLOYEE E, JOBS J
WHERE E.EID = J.EID AND
E.STATE = '<%=state%>' AND
current_date - E.STARTDATE > <%=minExp%>
AND J.DESC = '<%=jobDesc%>'
</h2g2j:text>



You could then in other subsequent pages use that StringBuffered pool of text by referencing it:
RunNext.jsp

<h2g2j:text ref="sesquery" scope="session"/>


<%
jdbcConnection.submit(query);
%>



RunFirst.jsp must be run once before any other page that would reference the session buffered text "sesquery". The ref invocation is necessary as it is an instruction to search for the session attribute "sesquery", whose object would be hooked up with the page variable "sesquery" by the servlet container's session handler.

Therefore, if you have a few voluminous query texts that tend to be reused frequently across the pages throughout a session, you could have an initial JSP that loads those texts into session buffer once. Rather than redefining common blocks of texts at every JSP.

No comments:

Post a Comment