当前位置: 技术问答>java相关
?? 在后台生成一个html页面,用来存档 ??
来源: 互联网 发布时间:2015-02-23
本文导语: 在jsp页面生成后,在后台生成一个它的html页面,用来存档 | 不难的,用文件操作即可实现。 给你一个我以前写的类:CreateHtml.java package HtmlUtil; import java.io.*; import java.util.*; public class Cre...
在jsp页面生成后,在后台生成一个它的html页面,用来存档
|
不难的,用文件操作即可实现。
给你一个我以前写的类:CreateHtml.java
package HtmlUtil;
import java.io.*;
import java.util.*;
public class CreateHtml
{
private class BlockTag
{
public String Tag = null;
public String replaceString = null;
public BlockTag(String Name,String Replace)
{
Tag = "";
replaceString = Replace;
}
}//end subclass
private Vector replaceTags = new Vector();
private String templateName = null;
private String outfileName = null;
public CreateHtml(String TemplateName,String FileName)
{
templateName = TemplateName;
outfileName = FileName;
}
protected void finalize()
{
replaceTags.removeAllElements();
}
public void AddTag(String Name,String Replace)
{
BlockTag item = new BlockTag(Name,Replace);
replaceTags.addElement(item);
}
private String isTag(String str)
{
Enumeration items = replaceTags.elements();
str = str.trim();
while(items.hasMoreElements())
{
BlockTag item = (BlockTag) items.nextElement();
if( str.equals(item.Tag) )
return item.replaceString;
else continue;
}
return null;
}
public void Write()
{
try {
BufferedReader in = new BufferedReader(new FileReader(templateName));
PrintWriter out = new PrintWriter(new FileWriter(outfileName),true);
String tempStr = null;
String str = null;
while( (tempStr = in.readLine()) != null )
{
if( (str = isTag(tempStr)) != null )
{
out.println(str);
}
else
{
out.println(tempStr);
}
}
out.close();
}//end try
catch(FileNotFoundException fx)
{
System.err.println("file can found!");
}
catch(IOException ix)
{
System.err.println("IO error");
}
}
}//end class
给你一个我以前写的类:CreateHtml.java
package HtmlUtil;
import java.io.*;
import java.util.*;
public class CreateHtml
{
private class BlockTag
{
public String Tag = null;
public String replaceString = null;
public BlockTag(String Name,String Replace)
{
Tag = "";
replaceString = Replace;
}
}//end subclass
private Vector replaceTags = new Vector();
private String templateName = null;
private String outfileName = null;
public CreateHtml(String TemplateName,String FileName)
{
templateName = TemplateName;
outfileName = FileName;
}
protected void finalize()
{
replaceTags.removeAllElements();
}
public void AddTag(String Name,String Replace)
{
BlockTag item = new BlockTag(Name,Replace);
replaceTags.addElement(item);
}
private String isTag(String str)
{
Enumeration items = replaceTags.elements();
str = str.trim();
while(items.hasMoreElements())
{
BlockTag item = (BlockTag) items.nextElement();
if( str.equals(item.Tag) )
return item.replaceString;
else continue;
}
return null;
}
public void Write()
{
try {
BufferedReader in = new BufferedReader(new FileReader(templateName));
PrintWriter out = new PrintWriter(new FileWriter(outfileName),true);
String tempStr = null;
String str = null;
while( (tempStr = in.readLine()) != null )
{
if( (str = isTag(tempStr)) != null )
{
out.println(str);
}
else
{
out.println(tempStr);
}
}
out.close();
}//end try
catch(FileNotFoundException fx)
{
System.err.println("file can found!");
}
catch(IOException ix)
{
System.err.println("IO error");
}
}
}//end class
|
用URL取得网页内容存盘
URL myURL=new URL("http://XXX.test.jsp");
InputStream in = myURL.openStream();
BufferReader bf = new BufferReader(in);
StringBuffer sb = new StringBuffer();
String b;
while((b= bf.readLine())!=null){
sb.append(b);
}
URL myURL=new URL("http://XXX.test.jsp");
InputStream in = myURL.openStream();
BufferReader bf = new BufferReader(in);
StringBuffer sb = new StringBuffer();
String b;
while((b= bf.readLine())!=null){
sb.append(b);
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。