Me again
Here is the solution I've adopted: A special jsp which will compile
all other jsps within the webapp:
-----------------------------------------------------------------------
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="javax.servlet.*,javax.servlet.http.*,javax.servlet.jsp.*"
%>
<%@ page import="java.util.Set,java.util.Iterator,java.io.IOException"
%>
<%!
private void compileAllJsps(PageContext pageContext, JspWriter out,
HttpServletRequest request, HttpServletResponse response, String
uripath) throws IOException, ServletException {
Set set = pageContext.getServletContext().getResourcePaths(uripath);
for (Iterator iter = set.iterator(); iter.hasNext()
{
String uri = (String) iter.next();
if (uri.endsWith(".jsp")) {
out.write("<li>"+ uri +"</li>");
out.flush();
RequestDispatcher rd =
getServletContext().getRequestDispatcher(uri);
if (rd == null) {
throw new Error(uri +" - not found");
}
rd.include(request, response);
} else if (uri.endsWith("/")) {
compileAllJsps(pageContext, out, request, response, uri); //
process subfolders
}
}
}
%>
<html>
<head><title>Precompiling *.JSPs</title></head>
<body>
<h4>Precompiling *.JSPs:</h4>
<ul>
<%
HttpServletRequest req = new HttpServletRequestWrapper(request) {
public String getQueryString() {
return "jsp_precompile=true";
};
};
compileAllJsps(pageContext, out, req, response, "/");
%>
</ul>
<h4>Done.</h4>
</body>
</html>
-----------------------------------------------------------------------
It works with Tomcat 4.1.27, and I can't see any reason why it would
not work in any other Servlet 2.3 and JSP 1.2 compatible container...
Alex Vassiliev
POWERWARE (New Zealand)