如何将动态jsp或其他动态页面生成静态html页面
1个回答
展开全部
import java.net.URLConnection;/*** 将信息发布为静态页面
* @author bzwang**/
public class DynInfo2Html {/*** 将信息转化为静态html
* @param sSourceUrl 动态信息访问URL
* @param sDestDir 存储为静态文件的目录
* @param sHtmlFile 生成的静态文件名,可以按信息的唯一ID+.html命名
* @throws IOException*/public static void convert2Html(String sSourceUrl,String sDestDir,String sHtmlFile) throws IOException{int HttpResult;
URL url=new URL(sSourceUrl);
URLConnection urlconn=url.openConnection();
urlconn.connect();
HttpURLConnection httpconn=(HttpURLConnection)urlconn;
HttpResult=httpconn.getResponseCode();
if(HttpResult!=HttpURLConnection.HTTP_OK) {}else {InputStreamReader isr =
new InputStreamReader(httpconn.getInputStream());
BufferedReader in = new BufferedReader(isr);
String inputLine;
if(!sDestDir.endsWith("/"))sDestDir+="/";
FileOutputStream fout = new FileOutputStream(sDestDir+sHtmlFile);
while ((inputLine = in.readLine()) != null) {
fout.write(inputLine.getBytes());}in.close();
fout.close();}}
* @author bzwang**/
public class DynInfo2Html {/*** 将信息转化为静态html
* @param sSourceUrl 动态信息访问URL
* @param sDestDir 存储为静态文件的目录
* @param sHtmlFile 生成的静态文件名,可以按信息的唯一ID+.html命名
* @throws IOException*/public static void convert2Html(String sSourceUrl,String sDestDir,String sHtmlFile) throws IOException{int HttpResult;
URL url=new URL(sSourceUrl);
URLConnection urlconn=url.openConnection();
urlconn.connect();
HttpURLConnection httpconn=(HttpURLConnection)urlconn;
HttpResult=httpconn.getResponseCode();
if(HttpResult!=HttpURLConnection.HTTP_OK) {}else {InputStreamReader isr =
new InputStreamReader(httpconn.getInputStream());
BufferedReader in = new BufferedReader(isr);
String inputLine;
if(!sDestDir.endsWith("/"))sDestDir+="/";
FileOutputStream fout = new FileOutputStream(sDestDir+sHtmlFile);
while ((inputLine = in.readLine()) != null) {
fout.write(inputLine.getBytes());}in.close();
fout.close();}}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询