You can define methods that you can use inside JSPs. You to use
declearations and not scriptlets to it:
<%!
public String foo() {
return "Hello World";
}
%>
However... I do not know whether you can create a library of these methods
in a JSP and include them in another JSP.
-----Original Message-----
From: Maggs Andy [mailto:[EMAIL PROTECTED]]
Sent: 28 March 2000 11:44
To: [EMAIL PROTECTED]
Subject: Re: include file with multiple functions ?
As far as I know, you cannot define Java functions in JSP. It would be
better to put the functions in a class anyway and either create an instance
of the class in code or use jsp:useBean.
e.g. create a class called MyClass.class with your functions in
In your JSP page import the relevant class/package in the page directive and
do the following:
<%
// create an instance of MyClass
MyClass objClass = new MyClass();
%>
<%=objClass.foo2() %>
Andy
-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Decancq, Michiel
Sent: 28 March 2000 10:38
To: [EMAIL PROTECTED]
Subject: include file with multiple functions ?
Hello,
I would be very glad to receive an answer to the following question :
How can I remove all the coding in a JSP-page to a JSP page that I can
include ? For example, say that I have the following JSP-page:
<html>
<head>
<jsp:include page="GenericFunctions.jsp" flush="true"/>
</head>
<body>
<%=foo1();>
<BR>
<%=foo2();>
<BR>
<%=foo3();>
<BR>
</body>
</html>
Within the body-tags, I want to show the output of three functions, for
example
public String foo1() { return "This is string 1"; }
public String foo2() { return "This is string 2"; }
public String foo3() { return "This is string 3"; }
These three functions should be defined in a JSP page called
"GenericFunctions.jsp", but I constantly get compilation errors when I
compile the page with content the above three functions enclosed within <%
and %>.
Many thanks,
Michiel
Michiel Decancq - partner - Emalaya nv
O Tel ++32-2-340 77 30
OOO Fax ++32-2-346 42 52
OOOOO GSM ++32-476-936 315
[EMAIL PROTECTED]
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets