In PHP it is possible to use scriptlet (<? or <%) tags in a subroutine in order to relocate the output on the page. Since any <% tags are included in the service method, is it possible to get scriptlets to work in any other function besides using a hacked inner class?

Serge Knystautas

No it isn't. Actually, you cannot write anything except Java code, i.e., you can't break out of scriptlets within a method. The reason is because when you're outside of a scriptlet, this implies that is HTML (or some text) that will be sent to a stream. When you're in your JSP, this is the "out" field, which is a quick reference to the response object's writer. When you're in your own method, there's no guarantee that you'll have a response object or a writer.

To create these kinds of subroutines, you can either hack an inner class (make sure you get the out field to be final, otherwise your inner class won't be allowed to access it), or you can use dynamic or static includes. We've found dynamic includes to be an effective way to create script-based subroutines.