日期:2014-05-17 浏览次数:20986 次
import java.io.*;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import com.qingke.logs.Logs;
public class GetStaticPage {
String host;
int port;
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public void jspToHtml(String jspPath,String jspName,String htmlPath,String htmlName){
try{
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(host,port);
String allpath=jspPath+jspName;
String allpathto = htmlPath+htmlName;
GetMethod get = new GetMethod(allpath);
client.executeMethod(get);
StringBuffer resultBuffer = new StringBuffer();
BufferedReader in = new BufferedReader(new InputStreamReader(get.getResponseBodyAsStream(),"GBK"));
String inputLine = null;
while( (inputLine = in.readLine()) != null ){
resultBuffer.append(inputLine);
resultBuffer.append("\n");
}
in.close();
String s = resultBuffer.toString();
//String s = get.getResponseBodyAsString();
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(allpathto)));
bw.write(s);
bw.close();
get.releaseConnection();
}catch (Exception ex ){
Logs.writerLog(ex.getMessage());
}
}
}
------解决方案--------------------
关注中
------解决方案--------------------