how to import a jsp from temp directory in jstl
I have some dynamically generated jsp content I'd like to (jstl) c:import
into another jsp page. Currently I have the dynamically generated jsp written to a file in the servlet temp directory (javax.servlet.context.tempdir
) but can't work out how I can import it since it is outside the servlet context.
Is there a way to import a jsp from the servlet temp directory, or can I somehow pre-process the jsp content without it having to be written to a file?
Previously I had this written to a file in the servlet context using getRealPath()
, but obviously it won't work in all deployments.
Thanks for any help!
[update] Ok, so I can't write a file except under a temp directory, and I can't use a jsp directly from a temp directory. Is there a way of passing the jsp content to the default jsp servlet directly to get the HTML output? How do you typi开发者_Python百科cally use dynamically generated jsp files? Can I implement a filter to pass in the jsp content from the tempo directory? Can I override with a HttpServletResponseWrapper or something?
That context attribute is of type File
, which provides a toURI
method. See if something like this works:
<%
File tempdir = application.getAttribute("javax.servlet.context.tempdir");
URI tempdirURI = tempdir.toURI();
application.setAttribute("tempdirURI", tempdirURI.toString());
%>
...
<c:import url="${tempdirURI}/path/to/generated.jsp"/>
If it does, it would actually be better practice to put the creation of tempdirURI into a ServletContextListener
. Or create an EL function...
精彩评论