I just started learning JSP technology, and came across a wall.
How do you output HTML from a method in <%! ... %> JSP declaration block?
This do
All you need to do is pass the JspWriter object into your method as a parameter i.e.
void someOutput(JspWriter stream)
Then call it via:
<% someOutput(out) %>
The writer object is a local variable inside _jspService so you need to pass it into your utility method. The same would apply for all the other built in references (e.g. request, response, session).
A great way to see whats going on is to use Tomcat as your server and drill down into the 'work' directory for the '.java' file generated from your 'jsp' page. Alternatively in weblogic you can use the 'weblogic.jspc' page compiler to view the Java that will be generated when the page is requested.
A simple alternative would be the following:
<%!
String myVariable = "Test";
pageContext.setAttribute("myVariable", myVariable);
%>
<c:out value="myVariable"/>
<h1>${myVariable}</h1>
The you could simply use the variable in any way within the jsp code