I want to invoke JSPs/servlets from non-request threads, e.g. to render
HTML for use in e-mails, etc.
I tried the simple-minded approach (with Tomcat 6.0.18):
ServletContext servletContext = MyContextMonitor.getContext(
"/myContextName" );
RequestDispatcher dispatcher =
servletContext.getRequestDispatcher( "/somePage.jsp" );
dispatcher.include( new Request( servletContext ), new Response() );
where Request and Response are mock HttpServletRequest and
HttpServletResponse implementations. Response's output stream and
writer are routed to System.out.
I get the dispatcher fine. I get output if I use
"/somePropertiesFile.properties" in place of "/somePage.jsp" -- but only
if I use include(), not forward(). I don't get output for /somePage.jsp
in either case.
Any ideas? Anyone /successfully /doing this sort of thing?
Is there an existing library for this that I'm overlooking? It seems
really bizarre that for all the time and energy invested in servlet and
JSP based HTML page generation that there's not a standard bridge to
using servlets and JSPs from other threads to generate HTML files,
e-mails, etc.
--
Jess Holle