在servlet中通过一个url地址得到网页的内容,并且保存为一个html,能实现吗? 没问题,可以把html当作一个文件打开,使用流传输,我做过这东西。不过我的代码已经不再了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不清楚楼主要干什么?是要把url指向的网页的内容保存下来?如果事的话。用HttpURLConnection不就可以了吗? import java.io.*;import java.net.*;import java.util.Date;class URLDemo{ public static void main(String args[]) throws Exception { System.out.println("starting...."); int c; URL url = new URL("http://www.sina.com.cn"); URLConnection urlcon = url.openConnection(); System.out.println("the date is : " + new Date(urlcon.getDate())); System.out.println("content_type:" + urlcon.getContentType()); InputStream in = rulcon.getInputStream(); while(((c=in.read())!=-1)) { System.out.println((char)c); } in.close(); }} 类似于保存成一个mht的web档案文件 URL url=new URL("http://192.168.0.109:8080/yinxing/content/12"); HttpURLConnection open=(HttpURLConnection)url.openConnection(); open.connect(); BufferedReader buf=new BufferedReader(new InputStreamReader(open.getInputStream())); String temp=null; while((temp=buf.readLine())!=null)System.out.println(temp); buf.close(); zhaoxichao(小西) HTM中的图片可以取得。但有前提就是你的把<IMG SRC..后面的图片的相对URL取出来(通过正则表达式),然后在通过HttpURLConnection来去图片。 import java.net.*;import java.io.*;public class URLConnectionReader{ public static void main(String[] args) throws Exception { URL yahoo = new URL("http://www.chinaren.com/"); URLConnection yc = yahoo.openConnection(); BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); }}这样可以得到你想要的HTML代码,然后把这些代码写到一个HTML文件不就完了吗 求赐教,怎样踢人? jsp myeclipse jdbc ssh文件上传 项目估算的问题 空指针错误是怎么回事 请各位帮帮忙 在struts中点击链接后将链接文字显示到文本框? eclipse插件损坏 初学者提问:怎么显示数据库单项?谢谢! 修改问题求救 求教有关smartupload的问题,有关就给分!! 一个动态背景的问题 做这个这样的http://www.lepalmier.de/网站在概在多少钱
是要把url指向的网页的内容保存下来?
如果事的话。用HttpURLConnection不就可以了吗?
import java.net.*;
import java.util.Date;class URLDemo
{
public static void main(String args[]) throws Exception
{
System.out.println("starting....");
int c;
URL url = new URL("http://www.sina.com.cn");
URLConnection urlcon = url.openConnection();
System.out.println("the date is : " + new Date(urlcon.getDate()));
System.out.println("content_type:" + urlcon.getContentType());
InputStream in = rulcon.getInputStream();
while(((c=in.read())!=-1))
{
System.out.println((char)c);
}
in.close();
}
}
HttpURLConnection open=(HttpURLConnection)url.openConnection();
open.connect();
BufferedReader buf=new BufferedReader(new InputStreamReader(open.getInputStream()));
String temp=null;
while((temp=buf.readLine())!=null)System.out.println(temp);
buf.close();
HTM中的图片可以取得。但有前提就是你的把<IMG SRC..后面的图片的相对URL取出来(通过正则表达式),然后在通过HttpURLConnection来去图片。
import java.io.*;
public class URLConnectionReader
{
public static void main(String[] args) throws Exception
{
URL yahoo = new URL("http://www.chinaren.com/");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
}
这样可以得到你想要的HTML代码,然后把这些代码写到一个HTML文件不就完了吗