- 浏览: 278263 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (208)
- Oracle (21)
- webservice (7)
- java (33)
- java序列化反序列化 (0)
- weblogic (4)
- ajaxFileUpload (2)
- uploadify (1)
- jquery (7)
- MAXIMO (4)
- smartgit (1)
- css (3)
- POI (1)
- photoshop (0)
- linux (1)
- highchart 动态添加数据 (0)
- highchart (5)
- json (7)
- spring (11)
- maven (10)
- app (7)
- ASCII (1)
- mysql (26)
- excel (1)
- tomcat (3)
- bootstrap (1)
- ztree (2)
- dubbo (4)
- nginx (5)
- hadoop (3)
- osgi (3)
- ext (2)
- cxf (4)
- hibernate (1)
- 协议 (1)
- axis2 (1)
- javascript (2)
- vue (2)
- EhCache (2)
- Quartz (1)
- sqlite (1)
- saas (0)
- ionic (1)
- developer (1)
- maven 常用命令 (1)
- eclipse (1)
- mac (2)
- mongoldb (1)
- svn (1)
最新评论
-
wyb243:
大家千万不要按照这个写!!!PreparedStatement ...
JdbcTemplate插入后获取自增ID -
北雁南飞33:
有源码分享吗
自定义分页标签结合spring mvc、bootstrap、mybatis、mysql的使用 -
xcg992224:
大哥 不需要手动调用回收 是你在for的里面不应该每次都去ne ...
Java 垃圾回收测试
1、定义写一个上传附件的jsp文件uploadfile.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.io.*;"%>
<html>
<body>
<%
InputStream in = request.getInputStream();
request.setCharacterEncoding("utf-8");
String name = request.getHeader("filename");
if (name != null && !"".equals(name)) {
String savepath = request.getHeader("savepath");
String path = request.getSession().getServletContext()
.getRealPath("/");
File file = new File(path + "\\" + savepath + "\\" + name);
FileOutputStream fos = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int bytes = 0;
while ((bytes = in.read(buffer)) != -1) {
fos.write(buffer, 0, bytes);
}
fos.flush();
fos.close();
in.close();
}
%>
</body>
</html>
2、java代码,通过后台代码调用url上传附件
public static void httpConnectionUpload(String fname,String savepath,InputStream ins) {
try {
/****urlStr为http://localhost:7001/DOCLINKS/uploadfile.jsp**/
String urlStr=PropertiesHelper.getValue("httpconn.upload.url");
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setChunkedStreamingMode(1024 * 1024);
conn.setRequestMethod("POST");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("Charsert", "UTF-8");
conn.setRequestProperty("Content-Type", "multipart/form-data;charset=utf-8;file=" +fname);
conn.setRequestProperty("filename", fname);//文件名
conn.setRequestProperty("savepath", savepath);//存储文件夹
OutputStream out = new DataOutputStream(conn.getOutputStream());
DataInputStream in = new DataInputStream(ins);
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = in.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
in.close();
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.io.*;"%>
<html>
<body>
<%
InputStream in = request.getInputStream();
request.setCharacterEncoding("utf-8");
String name = request.getHeader("filename");
if (name != null && !"".equals(name)) {
String savepath = request.getHeader("savepath");
String path = request.getSession().getServletContext()
.getRealPath("/");
File file = new File(path + "\\" + savepath + "\\" + name);
FileOutputStream fos = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int bytes = 0;
while ((bytes = in.read(buffer)) != -1) {
fos.write(buffer, 0, bytes);
}
fos.flush();
fos.close();
in.close();
}
%>
</body>
</html>
2、java代码,通过后台代码调用url上传附件
public static void httpConnectionUpload(String fname,String savepath,InputStream ins) {
try {
/****urlStr为http://localhost:7001/DOCLINKS/uploadfile.jsp**/
String urlStr=PropertiesHelper.getValue("httpconn.upload.url");
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setChunkedStreamingMode(1024 * 1024);
conn.setRequestMethod("POST");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("Charsert", "UTF-8");
conn.setRequestProperty("Content-Type", "multipart/form-data;charset=utf-8;file=" +fname);
conn.setRequestProperty("filename", fname);//文件名
conn.setRequestProperty("savepath", savepath);//存储文件夹
OutputStream out = new DataOutputStream(conn.getOutputStream());
DataInputStream in = new DataInputStream(ins);
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = in.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
in.close();
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
发表评论
-
System.getProperty()
2018-01-03 15:05 615System.getProperty("java. ... -
Spring/SpringMVC在启动完成后执行方法
2017-09-24 12:22 521在某些情况下,有可能你会有这种需求:在Spring/Spri ... -
java modbus 32位浮点数解析
2017-09-07 11:24 2104package com; import java.te ... -
mqtt发布订阅fusesource版本
2017-08-29 10:56 1490fusesource版本:mqtt-client-1.10. ... -
Java socket字节流传输的示例
2017-02-22 12:27 847package com.yuan.socket; im ... -
DatabaseMetaData类的使用
2016-10-15 23:30 757DatabaseMetaData类 DatabaseM ... -
JAVA组合字符串,长度不足用0补齐
2016-06-02 23:40 1328public class Test { publ ... -
apache base64文件转换
2016-02-18 19:11 1324package com.fengyunhe.helper.i ... -
java读取大数据文件性能比较
2016-02-18 10:54 2075通过使用java提供的io,scanner类,apache ... -
java反射调用方法
2016-02-18 10:48 1602public class InvokeTester { ... -
获取request里的所有参数及参数名
2016-02-16 17:48 709获取request里的所有参数及参数名(参数名自动获取) ... -
查找jar中的pom文件
2016-01-21 09:51 1322/** * 查找dependency节点 ... -
JDBC批量Insert深度优化
2016-01-12 21:10 564JDBC批量Insert深度优化(有事务) 环境: ... -
java 获取上月、一个月最后一天、周一、周日、本月日期
2016-01-08 16:18 6445获取上月:Calendar c = Calendar.get ... -
ehcache memcache redis 三大缓存男高音
2015-12-03 09:57 576Ehcache 在java项目广泛的使用。它是一个开源的、设 ... -
java 文件 读取目录下的所有文件(包括子目录)
2015-09-12 09:52 1631package com.jxtech.filetool; ... -
XMLGregorianCalendar与Date之间转换
2015-07-17 10:57 3442import java.text.SimpleDateFor ... -
StringBuffer内容清空效率比较
2015-07-14 11:18 716在开发程序的时候,经常使用StringBuf ... -
Java 垃圾回收测试
2015-06-26 10:27 966测试用例 ObjA public class ObjA ... -
Web.xml 加载顺序
2015-06-26 10:16 642大类顺序:context-param -> list ...
相关推荐
一个 定时向网络访问数据 的程序,地震速报--HttpURLConnection与 Service 侦测服务, 详情请参见 http://blog.csdn.net/aduovip/article/details/17054129
http请求在Android开发中是必不可少的,现在我写了一个关于http get请求文本数据的例子希望能和大家交流学习
HttpURLConnection的get,post和图片加载
NULL 博文链接:https://hilary3113.iteye.com/blog/935239
主要介绍了JAVA通过HttpURLConnection 上传和下载文件的方法,非常具有实用价值,需要的朋友可以参考下
主要介绍了java后台调用HttpURLConnection类模拟浏览器请求实例,该实例可用于接口调用,具有一定的实用价值,需要的朋友可以参考下
Java自带的HttpURLConnection访问接口文件上传, 含普通参数值传递和文件传递
java网络请求工具类 HttpURLConnection post请求工具类HttpURLConnection httpURLConnection = (HttpURLConnection) url .openConnection(); httpURLConnection.setRequestMethod("POST");// 提交模式
主要介绍了Java 中HttpURLConnection附件上传的实例详解的相关资料,希望通过本文大家能掌握这样的知识内容,需要的朋友可以参考下
Android-HttpURLConnection说明lib-http 后续不再单独在此维护,统一合并到AndroidAppFactory 中继续维护,对应Git地址为:AndroidAppFactory:对应组件库为:LibHttpCommon & LibHttpAdvanced调用事例参考:简介一...
【Java】java.net.HttpURLConnection的使用
java实现多次HttpURLConnection共享session,发送两次请求共享同一个session,这样做爬虫的时候就可以爬网站登录后能看到的内容了
java HttpURLConnection示例 HttpURLConnection工具
本人原创测试了百度,搜狗,360搜索都可以获取重定向后的真实地址,直接运行就可以,也可以根据自己项目具体修改功能。java使用HttpURLConnection获取百度搜狗360搜索链接重定向真实目标链接地址url。
使用HttpURLConnection实现断点续传
用于对基于HTTP的服务进行抓取 HttpClient 现在是HttpComponents 把问题搞复杂了 其实Java内置的HttpURLConnection很好的 内含文档 使用方法见http: blog csdn net jdgdf566 article details 16357677
实例Demo程序来示范使用HttpURLConnection实现多线程下载。 使用多线程下载文件可以更快完成文件的下载,因为客户端启动多条线程进行下载就意味着服务器也需要为该客户端提供响应的服务。假设服务器同时最多服务100...
用于基于Java HttpURLConnection类测试https代理设置的Java代码。 该代码实际上可以连接到任何URL,但仅响应https.proxyUser和https.ProxyPassword系统属性。 用法: $ java <java> -jar testwebpage.jar sherif@...
HttpURLConnection文件下载\httpURLConnection文件下载