<FORM id="form1" METHOD=POST ACTION="publishAction.jsp" onSubmit="return check();">
获取apache目录<br/>
发布css,js,img等静态资源文件<br/>
<br/>
<br/>
<%String docBase = pageContext.getServletContext().getRealPath("/");%><br/>
显示出 <%=docBase%> 文件列表<br/>
<%
File f = new File(docBase);
%>
<table class="listTable">
<tr>
<th>JSP文件</th>
<th>启用缓存</th>
<th>缓存文件</th>
<th></th>
<th></th>
</tr>
<c:forEach var="filename" items="<%=f.list()%>">
<c:if test="${fn:endsWith(filename, '.jsp')}">
<tr>
<td>${filename}</td>
<td>启用</td>
<td>
<%
String fileName = (String)pageContext.findAttribute("filename");
fileName = fileName.replaceAll(".jsp","_cache.html");
if(new File(docBase+"cache"+File.separatorChar+fileName).exists()){
out.println(fileName);
}else{
}
%>
</td>
<td><a href="deleteCacheAction.jsp?page=${filename}" title="清除缓存">清除缓存</td>
<td><a href="publishAction.jsp?page=${filename}" title="重新生成">重新生成</a></td>
</tr>
</c:if>
</c:forEach>
</table>
</FORM>
public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// Pass control on to the next filter
//
//request.setCharacterEncoding("utf-8");
HttpServletRequest req = (HttpServletRequest) request;
String path = req.getServletPath();
if ((!path.startsWith("/admin")) && path.endsWith(".jsp")&&req.getParameter("makeCache")==null) {
path = path.replaceAll(".jsp", "_cache.html");
System.out.println(path);
System.out.println(req.getRequestURI());
System.out.println(req.getRequestURL());
request.getRequestDispatcher("/cache"+path).forward(request, response);
} else {
chain.doFilter(request, response);
}
}
/**
* Place this filter into service.
*
* @param filterConfig The filter configuration object
*/
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.enable = filterConfig.getInitParameter("enable");
}
--------------------------------------------------------------------------------