The JSP implicit variables (request, application, out, etc...) are only available in the service method sections of the JSP (not in <%! ...%> blocks).
If you want to print to the page from one of your methods, you'll have to pass a reference to the printWriter to the function. If this seems ugly, it is.
The standard approach, these days, is to conduct all of your business logic in your
servlets and/or beans and use JSTL to iterate over the results in the JSP.