Setting aside the issue of whether or not this is a good idea :
1) create a custom attribute processor (extending AbstractUnescapedTextChildModifierAttrProcessor?)
that could handle something like <div th:jsp="/foo/bar/baz.jsp">jsp content goes here</div>
2) make sure the HttpServletRequest and HttpServletResponse are available to the attribute processor (put them in the context)
3) create a class that wraps HttpServletResponse and have all the methods 'pass through' except
getWriter() which should return a PrintWriter that is backed by a CharArrayBuffer. You'll also need a
method that returns you the contents of the buffer. Wrap the HttpServletResponse with an instance of
this class, so that when the jsp content is written to the response it is actually being written to a buffer.
Thymeleaf writes out the whole result of its template right at the end - if you don't capture the jsp
output it will be written out before any of the thymeleaf content.
4) do a normal request.getRequestDispatcher(jspName).include(request, wrappedResponse)
5) return the content of the HttpServletResponse buffer.
You'd need to be very careful with your HttpServletResponse wrapper class otherwise you might get odd
behaviour in some cases (e.g. with WebSphere dynacache for example - or other things that muck about
with the HttpServletResponse as much as you)
There is no way to execute a fragment of JSP from Thymeleaf, because they are different technologies and Thymeleaf does not understand JSP's syntax and language (in the same way the JSP engine does not understand Thymeleaf's).
But you can insert *the result* of executing a JSP page as a fragment in a Thymeleaf template.
Now add a UrlTemplateResolver to your Thymeleaf configuration, setting viewNames="*.do" and prefix="http://myapp/".
Finally, in your Thymeleaf template, insert a fragment using an XPath expression instead of a fragment name. This allows you to insert non-thymeleaf fragments into your Thymeleaf templates. XPath expressions are expressed between square brackets:
You both are right, it is possible to create a Thymeleaf Processor to include some external content in the style of the c:import JSTL tag:
<c:import url="..." />
But the original question was asking about a way "to reuse some custom tags we already have for pagination" and I think this is not possible because Thymeleaf and JSP should share some state objects, or at least it would be very tricky and difficult.