Topic: 怎样编写上传程序?

  Print this page

1.怎样编写上传程序? Copy to clipboard
Posted by: AT
Posted on: 2003-03-24 09:22

我想编写一个上传的SERVLET或BEAN
有哪位能简单描述一下编写上传程序的思想或解决方法吗?
谢谢!!!

2.Re:怎样编写上传程序? [Re: AT] Copy to clipboard
Posted by: floater
Posted on: 2003-03-25 02:05

There are codes on the net to do so. Do a search.

Structs has a servlet, there is one more, I don't remember.

3.Re:怎样编写上传程序? [Re: AT] Copy to clipboard
Posted by: chaos
Posted on: 2003-03-25 03:33

1. read the spec. http://www.ietf.org/rfc/rfc1867.txt
2. GOTO Orielly servlet collection site : http://www.servlets.com/cos/index.html SELECT class MultipartRequest (It can now with the latest release handle internationalized content )
3.Do a search. Big Smile There're lots of examples you can find.

4.Re:怎样编写上传程序? [Re: chaos] Copy to clipboard
Posted by: gunrose
Posted on: 2003-03-25 13:00

There is no Servlet/JSP API where you can retreive the uploaded file. However, you can use a third party package such as com.oreilly.servlet from Oreilly. You can take a look at the .java sources in this package to see how the uploaded files and parameters are parsed out. Here is a code snippet using the MultipartParser

import java.io.*;
import com.oreilly.servlet.multipart.*;

int maxFileSize = 5 * 1024 * 1024; // 5MB max
String uploadDir = "/tmp/";
MultipartParser parser =
new MultipartParser(request, maxFileSize);
Part p = null;
long numBytes = 0;

while((p = parser.readNextPart()) != null)
{
if(p.isParam())
{ //Do something here with other form
//elements that are not files
}
else if(p.isFile())
{ FilePart fp = (FilePart)p;
// my_file is the name of the file
// declared in the html form
if (p.getName().equals("my_file"))
{ numBytes =
fp.writeTo(new File(uploadDir));
}
}
}

Another solution to make handling multipart/form-data POST request easier is to use the MultipartFilter class. For more information on MultipartFilter class, check out the com.oreilly.servlet package.

5.Re:怎样编写上传程序? [Re: AT] Copy to clipboard
Posted by: AT
Posted on: 2003-03-26 16:53

谢谢楼上的各位朋友!!
小弟试试看。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923