实现任何页面静态化源码
来源:互联网 发布:红蜘蛛调色软件 编辑:程序博客网 时间:2024/05/01 17:34
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class HomeStaticAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String sUrl = request.getParameter("sUrl"); //需要静态化的页面
String charset = request.getParameter("charset"); //编码
String sHtmlFile = request.getParameter("sHtmlFile");//静态化后页面的名称
String sSavePath = request.getSession().getServletContext().getRealPath("/"+"statichtml"); //静态化后的页面保存的路径
//String sSavePath = "E://cts//huajiao//WebRoot";
//System.out.println("sSavePath........."+sSavePath);
int HttpResult;
URL url = new URL(sUrl);
URLConnection urlconn = url.openConnection();
// 抽象类 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);
//BufferedReader in = new BufferedReader(new UnicodeReader(in, Charset.defaultCharset().name());
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();
}
String templateContent="";
FileInputStream fileinputstream=new FileInputStream(sSavePath+"/" + sHtmlFile);
int length=fileinputstream.available();
byte byts[]=new byte[length];
fileinputstream.read(byts);
fileinputstream.close();
templateContent=new String(byts);
// String a="/"";
// String b=".";
// String c="</jsp:include>";
// String ab="<jsp:include page="+a+"/jsp/index_html/online"+b+"jsp"+a+">"+c;
// templateContent=templateContent.replaceAll("<!--Online-->", ab);
FileOutputStream fileoutputstream=new FileOutputStream(sSavePath + sHtmlFile);
byte outbyte[]=templateContent.getBytes("utf-8");
fileoutputstream.write(outbyte);
fileoutputstream.close();
return mapping.findForward("success_html");
}
}
- 实现任何页面静态化源码
- velocity实现页面静态化
- PHP页面静态化实现
- 如何实现页面静态化:
- PHP实现页面静态化
- 过滤器实现页面静态化
- PHP实现页面静态化
- php实现页面静态化
- php实现页面静态化
- PHP实现页面静态化
- php实现页面静态化
- php实现页面静态化
- php实现页面静态化(纯静态&&伪静态)
- 使用php实现伪静态化页面
- PHP伪静态化页面的实现
- asp.net静态化页面实现学习
- 用Freemarker实现页面静态化
- 使用php实现伪静态化页面
- ASP.Net 2.0窗体身份验证机制
- seo优化
- 纯DOS下的 TCP/IP编程
- 10个国外Ajax及Javascript实例资源网站
- 将 ASP.NET 2.0 应用程序服务配置为使用 SQL Server 2000 或 SQL Server 2005
- 实现任何页面静态化源码
- Java and XML_读书笔记_2010-05-17
- smbget smbput
- 2010年5月18日(变量和表达式)
- 开张除草
- Swing的设计是MVC的典范
- struts上传图片argument type mismatch错误
- Oracle Logminer 说明
- JNA实现Java调用Fortran