编写代码对所有JSP进行预编译
2008-04-10 19:42
393 查看
一些JSP容器(例如规范中的第8.4.2节点提到的)支持对JSP页面进行预编译的能力
为了预编译一个JSP页面, 我们访问这个页面需要使用?jsp_precompile这样的模式
例如:
http://hostname.com/mywebapp/mypage.jsp?jsp_precompile
这个JSP页面不会被执行,如果容器支持预编译,这个jsp页面将会按照要求被编译.
下面是一个JSP页面,这个页面将会扫描当前目录(包括子目录),并且预编译这些目录下所有的JSP文件.
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="javax.servlet.*"%>
<%@ page import="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);
}
}
}
%>
<html><head><title>Precompiling *.JSPs</title></head>
<body><h4>Precompiling *.JSPs:</h4>
<ul>
<%
HttpServletRequest req = new HttpServletRequestWrapper(request) {
public String getQueryString() {
// can be "jsp_precompile=true"
return "jsp_precompile";
};
};
compileAllJsps(pageContext, out, req, response, "/");
%>
</ul>
<h4>Done.</h4>
</body> </html>
主意:很多中间件服务器提供预编译JSP页面的工具(如EAServer,BEAWLS等)去检查一个JSPC命令文件.
转载请注明本文来自程式先锋网站 http://www.javabiz.cn
为了预编译一个JSP页面, 我们访问这个页面需要使用?jsp_precompile这样的模式
例如:
http://hostname.com/mywebapp/mypage.jsp?jsp_precompile
这个JSP页面不会被执行,如果容器支持预编译,这个jsp页面将会按照要求被编译.
下面是一个JSP页面,这个页面将会扫描当前目录(包括子目录),并且预编译这些目录下所有的JSP文件.
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="javax.servlet.*"%>
<%@ page import="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);
}
}
}
%>
<html><head><title>Precompiling *.JSPs</title></head>
<body><h4>Precompiling *.JSPs:</h4>
<ul>
<%
HttpServletRequest req = new HttpServletRequestWrapper(request) {
public String getQueryString() {
// can be "jsp_precompile=true"
return "jsp_precompile";
};
};
compileAllJsps(pageContext, out, req, response, "/");
%>
</ul>
<h4>Done.</h4>
</body> </html>
主意:很多中间件服务器提供预编译JSP页面的工具(如EAServer,BEAWLS等)去检查一个JSPC命令文件.
转载请注明本文来自程式先锋网站 http://www.javabiz.cn
相关文章推荐
- 编写代码对所有JSP进行预编译
- struts2对Action中所有方法进行输入校验(手工编写代码)
- 学习笔记------------------对Action中所有方法进行输入校验和对指定方法输入校验(手工编写代码和xml方式)
- 将Python代码嵌入C++程序进行编写的实例
- JAVA实现将磁盘中所有空文件夹进行删除的代码
- 将Python代码嵌入C++程序进行编写
- 用C语言编写一个去除C代码中所有的注释的部分
- 使用JAVA客户端对HDFS进行代码编写(五)
- iOS对项目中所有加阴影的代码进行优化
- 使用maven对jsp进行预编译
- 用JUnit4进行单元测试代码编写
- MyEclipse 编写 JSP 代码时很卡的解决办法
- 编写一个方法,对字符串进行排序,将所有变位词排在相邻的位置
- 如何编写脚本对项目代码进行分析(性能篇)
- 编写高质量代码改善C#程序的157个建议——建议17:多数情况下使用foreach进行循环遍历
- 使用Pycharm 社区版配合anaconda进行代码编写遇到的一些小问题汇总
- 在代码运行时或者在禁用“只要一个进程中断,就中断所有进程”选项时,不允许进行更改。
- 用Idea编写JSP程序进行Javaweb开发时,网页出现乱码怎么办?
- 使用JSP代码和使用JavaScript代码进行表单数据验证有什么不同?
- 【附代码】如何在私有链上编写、部署与以太坊进行交互的智能合约