- 浏览: 57123 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
liumingtong:
我想要你的联系方式.可以吗?要不你加我Q 3813774
success -
抛出异常的爱:
congdepeng 写道Liskov替换原则(LSP)
描 ...
设计原则 -
wumingshi:
楼主关于LSP的解释是错误的。LSP的精髓是,使用父类的代码可 ...
设计原则 -
liumingtong:
struts2的OGNL表达式
struts2的值栈
st ...
总结struts2 完成中······ -
Cindy_Lee:
Joy.zhang 写道
下面是具体的设计模式:
单例 ...
设计模式中11种
本文介绍利用jsp读取远程文件保存到本地的文章专题。
用jsp,读远程文件,保存到本地
读取网络文件有些不一样,我给你一个完整的代码吧,存成jsp就可以直接运行的。
<%@ page import="java.io.*"%>
<%@ page import="java.net.*"%>
<%@ page import="java.util.Properties"%>
<%
//?程文件路径
String s1 = "http://www.google.co.jp";
//本地存放路径
String s2 = "C:\\test.html";
URL urlfile = null;
HttpURLConnection httpUrl = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
File f = new File(s2);
//make proxy
String proxy = "192.168.224.12";
String port = "8080";
Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost",proxy);
systemProperties.setProperty("http.proxyPort",port);
try{
//?接指定的网??源,?取网??入流
urlfile = new URL(s1);
httpUrl = (HttpURLConnection)urlfile.openConnection();
httpUrl.connect();
bis = new BufferedInputStream(httpUrl.getInputStream());
}catch(Exception e){
System.out.println(e.toString());
}
try{
bos = new BufferedOutputStream(new FileOutputStream(f));;
byte[] b = new byte[1024];
while(bis.read(b)!=-1) {
bos.write(b);
}?
}catch(Exception e){
System.out.println(e.toString());?
}finally{
try{
bos.flush();
bis.close();
httpUrl.disconnect();
}catch(Exception e){
System.out.println(e.toString());?
}
}
?
%>
<center>
<form name="search" action="results.jsp" method="get">
<p>
<input name="query" size="44"/> Search Criteria
</p>
<p>
<input name="maxresults" size="4" value="100"/> Results Per Page
<input type="submit" value="Search"/>
</p>
??????? </form>
</center>
其中
//make proxy
String proxy = "192.168.224.12";//防火墙地址
String port = "8080"; //防火墙端口
Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost",proxy);
systemProperties.setProperty("http.proxyPort",port);
这一段是如果你的机器设定了防火墙,需要加上,如果是直接连上网,就不用。
用jsp,读远程文件,保存到本地
读取网络文件有些不一样,我给你一个完整的代码吧,存成jsp就可以直接运行的。
<%@ page import="java.io.*"%>
<%@ page import="java.net.*"%>
<%@ page import="java.util.Properties"%>
<%
//?程文件路径
String s1 = "http://www.google.co.jp";
//本地存放路径
String s2 = "C:\\test.html";
URL urlfile = null;
HttpURLConnection httpUrl = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
File f = new File(s2);
//make proxy
String proxy = "192.168.224.12";
String port = "8080";
Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost",proxy);
systemProperties.setProperty("http.proxyPort",port);
try{
//?接指定的网??源,?取网??入流
urlfile = new URL(s1);
httpUrl = (HttpURLConnection)urlfile.openConnection();
httpUrl.connect();
bis = new BufferedInputStream(httpUrl.getInputStream());
}catch(Exception e){
System.out.println(e.toString());
}
try{
bos = new BufferedOutputStream(new FileOutputStream(f));;
byte[] b = new byte[1024];
while(bis.read(b)!=-1) {
bos.write(b);
}?
}catch(Exception e){
System.out.println(e.toString());?
}finally{
try{
bos.flush();
bis.close();
httpUrl.disconnect();
}catch(Exception e){
System.out.println(e.toString());?
}
}
?
%>
<center>
<form name="search" action="results.jsp" method="get">
<p>
<input name="query" size="44"/> Search Criteria
</p>
<p>
<input name="maxresults" size="4" value="100"/> Results Per Page
<input type="submit" value="Search"/>
</p>
??????? </form>
</center>
其中
//make proxy
String proxy = "192.168.224.12";//防火墙地址
String port = "8080"; //防火墙端口
Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost",proxy);
systemProperties.setProperty("http.proxyPort",port);
这一段是如果你的机器设定了防火墙,需要加上,如果是直接连上网,就不用。
评论
2 楼
zhao103804
2010-07-16
http://www.google.co.jp
那个URL改成url=“http://www.google.co.jp”
savepath=“C:\\test.html”
zhao103804 写道
我怎么感觉你写的太麻烦点了吧,直接抓取那个页面不就行了吗?
public static void main(String[] args) {
String url = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionProvince";
url="http://vip.ibook8.com/2008/8/thinkingjava4th.rar";
String savepath = "f:\\thinkingjava4th.txt";
getAndSave(url,savepath);
}
public static void getAndSave(String url,String path) {
InputStream inputStream = null;
try {
URL surl = new URL(url);
URLConnection uc = surl.openConnection();
uc.connect();
inputStream = uc.getInputStream();
FileOutputStream fos=new FileOutputStream(path);
byte[] b = new byte[1024];
int len = 0;
while ((len = inputStream.read(b)) > 0) {
fos.write(b, 0, len);
}
inputStream.close();
fos.flush();
fos.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String url = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionProvince";
url="http://vip.ibook8.com/2008/8/thinkingjava4th.rar";
String savepath = "f:\\thinkingjava4th.txt";
getAndSave(url,savepath);
}
public static void getAndSave(String url,String path) {
InputStream inputStream = null;
try {
URL surl = new URL(url);
URLConnection uc = surl.openConnection();
uc.connect();
inputStream = uc.getInputStream();
FileOutputStream fos=new FileOutputStream(path);
byte[] b = new byte[1024];
int len = 0;
while ((len = inputStream.read(b)) > 0) {
fos.write(b, 0, len);
}
inputStream.close();
fos.flush();
fos.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
那个URL改成url=“http://www.google.co.jp”
savepath=“C:\\test.html”
1 楼
zhao103804
2010-07-16
我怎么感觉你写的太麻烦点了吧,直接抓取那个页面不就行了吗?
public static void main(String[] args) {
String url = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionProvince";
url="http://vip.ibook8.com/2008/8/thinkingjava4th.rar";
String savepath = "f:\\thinkingjava4th.txt";
getAndSave(url,savepath);
}
public static void getAndSave(String url,String path) {
InputStream inputStream = null;
try {
URL surl = new URL(url);
URLConnection uc = surl.openConnection();
uc.connect();
inputStream = uc.getInputStream();
FileOutputStream fos=new FileOutputStream(path);
byte[] b = new byte[1024];
int len = 0;
while ((len = inputStream.read(b)) > 0) {
fos.write(b, 0, len);
}
inputStream.close();
fos.flush();
fos.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String url = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getRegionProvince";
url="http://vip.ibook8.com/2008/8/thinkingjava4th.rar";
String savepath = "f:\\thinkingjava4th.txt";
getAndSave(url,savepath);
}
public static void getAndSave(String url,String path) {
InputStream inputStream = null;
try {
URL surl = new URL(url);
URLConnection uc = surl.openConnection();
uc.connect();
inputStream = uc.getInputStream();
FileOutputStream fos=new FileOutputStream(path);
byte[] b = new byte[1024];
int len = 0;
while ((len = inputStream.read(b)) > 0) {
fos.write(b, 0, len);
}
inputStream.close();
fos.flush();
fos.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
发表评论
-
jsp+tomcat+mysql&sevlet&javabean配置
2010-07-14 18:01 651在配置jsp开发环境的过 ... -
JSP中用bean封装常用的功能
2010-07-14 18:00 688本文介绍JSP中用bean封装常用的功能的文章专题。 1、建 ... -
JSP中关于html的转换技巧
2010-07-14 17:59 588本文介绍JSP中关于html的转换技巧的文章专题。 publ ... -
在JSP中设置HTTP应答头
2010-07-14 17:58 735本文介绍在JSP中设置HTTP应答头的文章专题。 Prime ... -
在JSP中访问CORBA服务对象实例
2010-07-14 17:58 770结合J2EE和CORBA可以充分 ... -
学习jsp与javascript结合在页面间传递参数
2010-07-14 17:57 1257本文介绍学习jsp与javascript结合在页面间传递参数的 ... -
JSP Commons FileUpload 组件上传文件的总结
2010-07-14 17:57 874本文介绍JSP Commons FileUpload 组件上传 ... -
JSP开发前设置
2010-07-14 17:56 657由于朋友问起我开发JSP前都要做些什么,就写了这篇东东。 ? ... -
JSP应用语法详解集三
2010-07-14 17:56 695本文介绍JSP应用语法详 ... -
JSP应用语法详解集二
2010-07-14 17:55 646本文介绍JSP应用语法详解集二的文章专题。 8)标签: 转发 ... -
JSP应用语法详解集一
2010-07-14 17:55 574本文介绍JSP应用语法详解:HTML注释,隐藏注释,Page指 ... -
提升JSP应用程序的7大绝招
2010-07-14 17:54 704本文的目的是通过对servlet和JSP的一些调优技术来极大地 ... -
JSP技巧之:session在何时被创建
2010-07-14 17:54 619本文介绍JSP技巧之:session在何时被创建的文章专题。 ... -
谈谈JSP的九个隐含对象
2010-07-14 17:53 847本文介绍谈谈JSP的九个隐含对象的文章专题,例如:储存和取得属 ... -
解决JSP与MySQL交互的中文乱码问题
2010-07-14 17:51 643首先实现了一个StringConvert bean(GBtoI ... -
JSP几个常见问题
2010-07-14 17:51 657本文介绍JSP几个常见问题的文章专题,Hashtable和 H ... -
JSp的Taglib Directiv语法,属性概述
2010-07-14 17:50 718指示(directive)允许您使用自定义的标签,为标签库命名 ... -
JSP连接SQL Server 2000系统详细配置
2010-07-14 17:50 571到SUN官方站点(http://java.sun.com)下载 ... -
JSP中标签库的深入研究
2010-07-14 17:50 611标签处理器和标签附加信息需要定位在JSP容器类载入器可以找到的 ... -
JSP中基于Session的在线用户统计分析
2010-07-14 17:49 720JSP作为后起之秀能够在 ...
相关推荐
本程序可用于在线编辑器提交内容时自动从网页中获得src图片地址,然后把远程图片下载到本地服务器,并把原网页中的地址替换成本地的地址。直接放在根目录上运行就行了。
工程作用:读取本地TXT文件并显示在JSP页面上 运行环境:Tomcat, JAVA EE6.0,搜狗高速浏览器 程序作者:Roy Liu 直接添加到MyEclipse中即可运行。 源程序内有代码注释。 已知BUG: 1、未输入文件地址时,会报错;...
纯jsp本地file文件读取小程序,实现简单的添加、读取、删选货物的功能
jsp读取excel表.rarjsp读取excel表.rarjsp读取excel表.rar 有列字源代码
利用Javabean+JSP 实现文件的上传、显示、下载 实现文件上传功能和下载功能,显示文件列表和读取文件内容功能。
通过文件流读取本地图片显示在JSP页面方法
Servlet读取XML文件实现JSP分页,Servlet读取XML文件实现JSP分页
此代码在服务端放置后,客户端进入该JSP页面能进行硬盘的增删改查、服务管理等等操作,甚至还有远程桌面,全部功能仅仅使用JSP一个文件实现。 大部分功能采用DOS命令,使用简单,页面友好人性化。
主要介绍了详解Java读取本地文件并显示在JSP文件中的相关资料,这里提供实例帮助大家实现这样的功能,希望能帮助到大家,需要的朋友可以参考下
实现文件上传到数据库下载到本地,路径可以自己选
jsp 读取XML代码,包括个文件,一个是JSP调用文件,一个是XML数据源结构文件,都在其中,注意XML数据源文件放的位置,经测试,可正常使用
用JSP实现把Word文件转换为HTML文件或TXT文件,然后用字符流读取转换后的文件,最后导入数据库.
把这个JSP页放在tomcat下,运行这个页就可以看到远程电脑的所有盘符,进入盘符即可上传下载文件,和灰鸽子很像哦!!!
使用JavaScript实现文件上传到本地服务器并获取到上传后文件所在路径,是由到JavaScript,java以及html页面。这个比较好,不是在jsp上获取路径,jsp太简单了,而且过时了,所以就在html页面实现了下功能,我主要是做...
目录的建立/检查与删除 ;charset=gb2312"%> *"%> <html> <head> 目录的建立/检查与删除</title> </head> <body> String path=request.getRealPath("");...//建立代表Sub目录的File对象,并得到它的一...
利用jsp实现文件上传下载,将文件上传到tomcat服务器之后下载。
java+jsp代码实现从FTP服务器上传下载文件。 里面给了java方法和jsp页面的代码。主要是实现从FTP服务器上面下载文件到自己本地文件夹下面。另外还给了几个网站供大家参考。
jsp读取大对象CLOB并生成xml文件示例源代码
jsp+flash web摄像保存图片到本地
有用DOM做XML处理.doc、用JDOM操作XML文.txt、在JSP开发中使用jdom解析临时存放数据的XML文件.txt、第8章_JSP实现对XML读写.pdf、从数据库Mysql读取数据转化为xml文档的Java类等,想实现jsp操作xml文件的人可以参考...