社区
Java SE
帖子详情
高分索取upload和download的源代码
olvest4000
2001-07-30 03:51:26
最近开发网站时出现了,不能实现upload和download功能,有谁帮帮忙啊,我一定重谢啊,谢谢先!
qq:4579751
email:olvest198@elong.com
...全文
118
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;
}
}
Tomcat的相对路径设置
今天一个web应用怎么也搞不定,原因是某个文件里有如下语句: InputStream is = new FileInputStream(*URL*); 其中URL是一个相对路径。部署好之后用ant启动Tomcat,发现一切正常,再用Tomcat自带的Restart脚本重启Tomcat,出错了,原因是取不到URL处的文件。debug了一下,发现用ant起和用脚本起Tomcat的根目录是不一样的(...
【java】设置tomcat将绝对路径替换成相对路径
【java】设置tomcat将绝对路径替换成相对路径 之前写项目时遇到一个问题: 上传图片后,数据库中我保存的是相对路径。但是我需要读取图片时必须通过绝对路径才能显示图片。 例如: 数据库中保存的图片路径是"/
upload
/123.jpg" ,而实际上我们需要的是“/home/zcx/image/
upload
/123.jpg”。 我们可以通过修改tomcat中的server.xml文件使程序运行时,将所有“/
upload
/”当作““/home/zcx/image/
upload
/” 方法1 打开tomcat
tomcat中如何设置相对路径指向绝对路径
在tomcat的server.xml中配置<Context path="/attached" docBase="E:\aic\attached" reloadable="true"/>,那么在jsp页面中http://127.0.0.1:8080/attached就是指向本机的E:\aic\attached文件夹 ...
设置form action相对路径和Tomcat deployment application context 实现对多模块的访问
问题源于 一点教程 Spring MVC快速入门(他用Eclipse, 我这里用IDEA) 当一个Project创建多个module,每个module的访问路径势必要加以区分,本文演示对于Web application(Servlet, web.xml, index.jsp)结构如何添加访问路径 简单说只有两步 1 index.jsp中, form action 添加相对访问路径, 如/模块名称 2 服务器Edit Configuration-Deployment-Application context中也
log4j日志相对路径,Tomcat(第三方和Springboot内置)参数catalina.home和catalina.base的设置
关于Log4j日志相对路径的配置请看:log4j 产生的日志位置设置 和 catalina.home、catalina.base . 由于我们在Log4j的配置中引入了系统属性${catalina.base},下面讲一下如何设置catalina.base,本质上就是在启动Tomcat的时候,给启动命令或脚本增加参数: 可以参考:操作系统的环境变量和Java系统属性 1.第三方Tomcat 在Tomcat安装路径/bin下面的catalina.bat或者相关的几个bat文件里面, 就有 CATALINA
Java SE
62,620
社区成员
307,251
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章