It's important not to forget that JSPs, like Servlets, are just
Java classes, and have access to all the functionality of the Java object model. For best performance and best maintainability,
you should make your JSPs as "slim" as possible. Make sure all code which is used more than once is shared rather than copied or included.
Including code with <@include> includes at compile time, and compiles an extra copy of the code for each JSP that uses it. This makes the delivered classes bigger and slows down compilation when you change the JSP code. Including something with <jsp:include> includes it at run time, every time the JSP is executed. Accessing code with "import" is the quickest both to compile (existing un-changed classes don't need to be re-compiled) and to execute.
I recommend writing your utility methods in one or more Java classes. If your methods do not require any initialization before use, make them static methods, and just call them. If they need initialization before use, you could make the class a bean, or use the Singleton
pattern to create self-initializing static methods.
An example of a JSP using an exteranl static method is as follows:
file: Utils.java
file: ex.jsp
To try this out, compile Utils.java and put the Utils.class in your WEB-INF/classes directory, then put ex.jsp in your document root. You can then call the JSP using
whatever/ex.jsp to use the default
string ("unknown") or as
whatever/ex.jsp?hello to translate "hello".
I hope this helps.