Background: Migrating an application from ball of mud to MVC. Many classes contain HTML building methods. Refactoring as I add features, I’m not looking for a complete rewrite.
I’d like to build some smaller views but need to render them in between some serious string building.
To compose my views is a jsp I would use <jsp:include /> tags. Is there similiar functionality I can call from a class? I’m looking at java.net.URL but it will require a little plumbing. The class already depends on the request object.
Thanks in advance.
Depends on what you mean “call from a class”. If your “class” is actually a Servlet, then you can get the RequestDispatcher from the servlet context, and call the
include()method from it. If your class is called from a servlet, you can pass the RequestDispatcher into it.But that’s a really bad idea.
Based on your description, I’d think of using a taglib for my “serious string handling”, and invoke those tags from the view.