社区
Java SE
帖子详情
高分索取upload和download的源代码
olvest4000
2001-07-30 03:51:26
最近开发网站时出现了,不能实现upload和download功能,有谁帮帮忙啊,我一定重谢啊,谢谢先!
qq:4579751
email:olvest198@elong.com
...全文
71
3
打赏
收藏
高分索取upload和download的源代码
最近开发网站时出现了,不能实现upload和download功能,有谁帮帮忙啊,我一定重谢啊,谢谢先! qq:4579751 email:olvest198@elong.com
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
olvest4000
2001-07-31
打赏
举报
回复
你的是不是有servlet写的代码啊???
olvest4000
2001-07-31
打赏
举报
回复
我的是所有的文件都要能实现upload和download!
softech
2001-07-30
打赏
举报
回复
拷了一个upload,自己看看,download太简单了吧,就懒得写了
/*
里面有不少bug,try your best
good luck
Demo_upload使用说明
html 文件
upload.java 文件
RFC 文档
*/
/*
Demo_upload使用说明
Demo_upload.html
使用Form中的TYPE=file来提交文件,一个<input type=file ....>提交一个文件
,
使用多个<input type=file ....>可以提交多个文件,提交之后文件被在D:\Jav
aWebServer2.0\servlets\file
目录下以原有文件名存储。对于其他TYPE类型的INPUT在SERVLET中不做处理仅仅
将其name和value在浏览器上
显示出来。
*Form的描述METHOD必须是POST,ENCTYPE必须是"multipart/form-data"
例:<form method=post action="/servlet/Demo_upload.class" ENCTYPE="mul
tipart/form-data">
Demo_upload.class(Servlet)
放于相应Web的Servlet目录下,由Form的submit激活。
详细程序流程见RFC文档:Request For Comments: 1867 和 upload.java程序中
的注释。
*/
/*
<html>
<title>UpLoad File</title>
<body>
<form method=post action="/servlet/Demo_upload.class" ENCTYPE="multipa
rt/form-data">
<input type=textbox name="text"><br>
<P>File: <input type=file name="USERFILE01">
<br>
<P>File: <input type=file name="USERFILE02">
<br>
<input type=submit name=submit value=submit>
<input type=reset name=reset value=reset>
</body>
</html>
*/
//*
//-------
//-
//- upload.java
//-
//- Author: AR Williamson
//- Date: May 1998
//- Copyright: Maybe used for non-commercial use.
//-
//-------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class upload extends HttpServlet {
public void doPost( HttpServletRequest _req, HttpServletResponse _re
s ) throws ServletException, IOException{
parseMultiForm pMF = new parseMultiForm( _req );
String param;
while ( (param = pMF.getNextParameter()) != null ){
if ( param.equalsIgnoreCase("USERFILE") ){
FileOutputStream OutFile = new FileOutputStream( pMF.getFilena
me() );
pMF.getParameter( OutFile );
OutFile.close();
}else{
System.out.println( "Key : " + param );
System.out.println( "Value: " + pMF.getParameter() );
}
}
_res.setStatus( HttpServletResponse.SC_NO_CONTENT );
}
}
class parseMultiForm extends java.lang.Object {
private ServletInputStream In;
private byte buffer[] = new byte[4096];
private String delimitor = null;
private String filename=null;
public parseMultiForm( ServletRequest _req ) throws IOException{
In = _req.getInputStream();
delimitor = _req.getContentType();
if ( delimitor.indexOf("boundary=") != -1 ){
delimitor = delimitor.substring( delimitor.indexOf("boundary=")+
9, delimitor.length() );
delimitor = "--" + delimitor;
}
}
private String readLine(){
try{
int noData = In.readLine( buffer, 0, buffer.length );
if ( noData != -1 )
return new String( buffer, 0, noData, "ISO-8859-1");
}catch(Exception E){}
return null;
}
void test() throws IOException{
String LineIn;
while( (LineIn=readLine()) != null )
System.out.println( LineIn );
}
public String getFilename(){
return filename;
}
public String getParameter(){
return readLine();
}
public String getNextParameter() {
try{
String LineIn=null, paramName=null;
while ( (LineIn=readLine()) != null ){
if ( LineIn.indexOf( "name=" ) != -1 ){
int c1 = LineIn.indexOf( "name=" );
int c2 = LineIn.indexOf( "\"", c1+6 );
paramName = LineIn.substring( c1+6, c2 );
if ( LineIn.indexOf( "filename=") != -1 ){
c1 = LineIn.indexOf( "filename=" );
c2 = LineIn.indexOf( "\"", c1+10 );
filename = LineIn.substring( c1+10, c2 );
if ( filename.lastIndexOf( "\\" ) != -1 )
filename = filename.substring( filename.lastIndexOf( "\" )+1 );
if ( filename.length() == 0 )
filename = null;
}
//- Move the pointer to the start of the data
LineIn = readLine();
if ( LineIn.indexOf( "Content-Type" ) != -1 )
LineIn = readLine();
return paramName;
}
}
}
catch( Exception E ){}
return null;
}
public boolean getParameter( OutputStream _Out ){
try{
int noData;
while ( (noData=In.readLine(buffer,0,buffer.length)) != -1 ){
if ( buffer[0] == '-' ){
if ( new String( buffer, 0, noData, "ISO-8859-1").indexOf(
delimitor) == 0 )
break;
}else
_Out.write( buffer, 0, noData );
}
_Out.flush();
return true;
}
catch( Exception E ){
System.out.println( E );
}
return false;
}
}
2018ASC题目
最近在做一些有关于2018届ASC的东西,考虑... 在预赛中,每个注册团队都需要提交一套文件,包括提案,优化
源代码
文件和输出文件(附录A中详细要求)。 提案需要用英文书写,并由ASC评估委员会审核。 2、提交指导
Unity3d 周分享(22期 2019.8.30 )
选自过去1~2周 自己所看到外文内容:https://twitter.com/unity3d 和各种其他博客来源吧 早就有了,抱歉才发! 1、 Unity Transform 性能优化摘要 https://qiita.com/sator_imaging/items/ff5811885f515a0a4998 ...
OpenCV4 | 如何让传统图像处理实现三十倍加速的顶级技能
点击上方“小白学视觉”,选择加"星标"或“置顶”重磅干货,第一时间送达OpenCV4 + CUDA从配置到代码.....引子一直有人在研习社问我,怎么去做OpenCV + CUDA的加速支持。其实网上用搜索引擎就可以找到一堆文章,但是...
朴素贝叶斯(西瓜数据集分类,社区恶意留言分类,垃圾邮件分类,新浪新闻分类),AODE分类器 代码实现
以下代码为本人学习后,修改或补充后的代码实现,数据集和原代码请参考:https://github.com/Jack-Cherish/Machine-Learning 社区恶意留言分类 import numpy as np def loadDataSet(): # 创建实验样本 postingLis
【Arduino】Learning Record
Arduino 是一块基于开放原始代码的 Simple i/o 平台,并且具有开发语言和开发 环境都很简单、易理解的特点。让您可以快速使用 Arduino 做出有趣的东西。 它是一个能够用来感应和控制现实物理世界的一套工具。 它由一...
Java SE
62,614
社区成员
307,327
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章