JSP页面静态化
2010-03-26 20:42
253 查看
package com.pageStatic;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
public class Test {
public static void convert2Html(String sUrl, String charset,
String sSavePath, String sHtmlFile) throws IOException {
int HttpResult;
URL url = new URL(sUrl);
URLConnection urlconn = url.openConnection();
System.out.println(sSavePath);
// 抽象类 URLConnection
// 是所有类的超类,它代表应用程序和 URL
// 之间的通信链接,通过在 URL 上调用
// openConnection 方法创建连接对象
urlconn.connect(); // 使用 connect 方法建立到远程对象的实际连接
HttpURLConnection httpconn = (HttpURLConnection) urlconn;
// 每个
// HttpURLConnection
// 实例都可用于生成单个请求,
// 但是其他实例可以透明地共享连接到
// HTTP 服务器的基础网络
HttpResult = httpconn. getResponseCode();
// getResponseCode可以从 HTTP
// 响应消息获取状态码
if (HttpResult != HttpURLConnection.HTTP_OK) {
} else {
InputStreamReader isr = new InputStreamReader(httpconn. getInputStream(),
charset);
BufferedReader in = new BufferedReader(isr);
String inputLine;
if (!sSavePath.endsWith("/")) {
sSavePath += "/";
}
FileOutputStream fout = new FileOutputStream(sSavePath + sHtmlFile);
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
fout.write((inputLine+"/n").getBytes());
}
in.close();
fout.close();
}
}
public static void main(String[] args) throws IOException {
Test ru = new Test();
String filePath =ru. getClass(). getResource("."). getPath().toString(); // 取得项目根目录
filePath = filePath.substring(1, filePath.indexOf("WEB-INF"));
convert2Html("http://localhost:8088/huajiao/index1.do", "UTF-8", filePath + "/","index.html");
}
}
参数sUrl可以是.do 也可以是jsp
把web.xml里的配置
<welcome-file-list>
<welcome-file>/sHtmlFile(生成之后的HTML文件,在此就是index.html)</welcome-file>
</welcome-file-list>
这样的话当页面发生改变的时候就需要静态化一次,而且这个静态化还是手动的,如果可以用缓存或者什么别的好方法,我介意还是用别的
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
public class Test {
public static void convert2Html(String sUrl, String charset,
String sSavePath, String sHtmlFile) throws IOException {
int HttpResult;
URL url = new URL(sUrl);
URLConnection urlconn = url.openConnection();
System.out.println(sSavePath);
// 抽象类 URLConnection
// 是所有类的超类,它代表应用程序和 URL
// 之间的通信链接,通过在 URL 上调用
// openConnection 方法创建连接对象
urlconn.connect(); // 使用 connect 方法建立到远程对象的实际连接
HttpURLConnection httpconn = (HttpURLConnection) urlconn;
// 每个
// HttpURLConnection
// 实例都可用于生成单个请求,
// 但是其他实例可以透明地共享连接到
// HTTP 服务器的基础网络
HttpResult = httpconn. getResponseCode();
// getResponseCode可以从 HTTP
// 响应消息获取状态码
if (HttpResult != HttpURLConnection.HTTP_OK) {
} else {
InputStreamReader isr = new InputStreamReader(httpconn. getInputStream(),
charset);
BufferedReader in = new BufferedReader(isr);
String inputLine;
if (!sSavePath.endsWith("/")) {
sSavePath += "/";
}
FileOutputStream fout = new FileOutputStream(sSavePath + sHtmlFile);
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
fout.write((inputLine+"/n").getBytes());
}
in.close();
fout.close();
}
}
public static void main(String[] args) throws IOException {
Test ru = new Test();
String filePath =ru. getClass(). getResource("."). getPath().toString(); // 取得项目根目录
filePath = filePath.substring(1, filePath.indexOf("WEB-INF"));
convert2Html("http://localhost:8088/huajiao/index1.do", "UTF-8", filePath + "/","index.html");
}
}
参数sUrl可以是.do 也可以是jsp
把web.xml里的配置
<welcome-file-list>
<welcome-file>/sHtmlFile(生成之后的HTML文件,在此就是index.html)</welcome-file>
</welcome-file-list>
这样的话当页面发生改变的时候就需要静态化一次,而且这个静态化还是手动的,如果可以用缓存或者什么别的好方法,我介意还是用别的
相关文章推荐
- 如何静态化JSP页面
- 页面静态化(JSP动态页面转静态化)
- JSP页面静态化总结之一使用URLRewrite实现url地址伪静态化
- JSP页面静态化
- 获取动态路劲指向的资源(jsp页面生成html 静态化;获取网站页面源码)
- jsp页面静态化
- jsp页面静态化
- JSP页面伪静态化
- 采用原生JSP实现页面静态化技术
- 页面静态化(JSP动态页面转静态化)
- 网摘-jsp页面静态化处理
- jsp页面静态化
- jsp页面静态化
- JSP页面静态化提高访问速度
- jsp页面静态化实例
- Java 常用工具类(16) : jsp和thymeleaf及其他模板页面静态化工具类
- jsp 页面静态化 java.net.MalformedURLException: no protocol: index.jsp和java.net.MalformedURLException: unknown protocol: d
- 页面静态化(JSP动态页面转静态化)
- jsp页面的静态化问题
- jsp页面静态化核心代码