|
发表于 2012-11-28 07:14:32
|
显示全部楼层
用jsp编写文件上载
如果你曾用VB编写文件上传的组件的话,那么用java编写文件上传的JAVABEAN十分容易。
下面的例子只是一个简版
package yuanyifileup;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.PageContext;
public class yuanyifileup
{www.bjkfp12.com,www.cckfp12.com,www.cskfp12.com,
PRivate ServletRequest request;
private ServletResp**e resp**e;
private ServletConfig config;
ServletInputStream DATA;
int FormSize;
File f1;
FileOutputStream os;
DataInputStream is;
String filename;
byte[] b;
byte t;www.dlkfp12.com,www.hfkfp12.com,www.hzkfp12.com,
boolean flag=false;
public yuanyifileup()
{ }
public void initialize(ServletConfig config,HttpServletRequest request,HttpServletResp**e resp**e) throws IOException
{
this.request=request;
this.resp**e=resp**e;
this.config=config;
DATA = request.getInputStream();
FormSize=request.getContentLength();
}
public void initialize(PageContext pageContext) throws IOException
{
request=pageContext.getRequest();
resp**e=pageContext.getResp**e();
config=pageContext.getServletConfig();
DATA = request.getInputStream();
FormSize=request.getContentLength();
}
public boolean setFilename(String s)
{
try
{
File f1=new File(s);
os=new FileOutputStream(f1);
}
catch(IOException e)
{return(false);}
return(true);
}
public void getByte()
{
int i=0;
try
{
is=new DataInputStream(DATA);
b=new byte[FormSize];
while (true)
{
try
{
t=is.readByte();
b[i]=t;
i++;
|
|