Piotrek wrote:
Hi all
My question is: Is it possible to make a function on a JSP page, that is a
set of JSP (esp. JSTL) tags?
I mean sth like:
<% public void fun()
{
%>
<sql:query var="tt">
select a,b
from c
order by a,b
</sql:query>
<c:forEach items="${tt.rows}" var="r">
<c:out value="${r.a}" />
<c:out value="${r.b}" />
</c:forEach>
<%
}
%>
so that I could use it later a few times? If yes, then how because the above
doesn't work.
JSP function declarations can only contain scripting (Java) code, but
another way to reuse a set of tags is to put them in a separate JSP
page and include it in all other pages where you need it:
fun.jsp:
<sql:query var="tt">
select a,b
from c
order by a,b
</sql:query>
<c:forEach items="${tt.rows}" var="r">
<c:out value="${r.a}" />
<c:out value="${r.b}" />
</c:forEach>
other.jsp:
And here's the list:
<jsp:include page="fun.jsp" />
You can use nested <jsp:param> tags to provide parameters to the
include page, if needed.
In JSP 2.0, a new way of creating custom tag libraries is introduced
as well. You will be able to create custom tags using a new type
of JSP file (a tag file) with regular JSP elements.
Hans
--
Hans Bergsten <[EMAIL PROTECTED]>
Gefion Software <http://www.gefionsoftware.com/>
Author of O'Reilly's "JavaServer Pages", covering JSP 1.2 and JSTL 1.0
Details at <http://TheJSPBook.com/>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com