请问各位,我在网上找到一段用JAVA写的CGI程序,不知道怎么用?

rong1999 2004-08-07 07:49:16
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoadFile extends HttpServlet
{

public LoadFile ()
{
}

public void init(ServletConfig config)
throws ServletException
{
super.init(config);
}

public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String workingpath = "c:\\upload\\";
javax.servlet.ServletInputStream DATA = req.getInputStream();
int FormSize = req.getContentLength() - 46;
byte buf[] = null;
int KB = 1024;
KB = KB <= FormSize ? KB : FormSize;
buf = new byte[KB];
DataInputStream is;
try
{
is = new DataInputStream(DATA);
is.read(buf);
}
catch(IOException e)
{
System.out.println(e.toString());
return;
}
String toke = "\"";
String temp = "";
int start1 = 0;
int start2 = 0;
int start3 = 0;
long i = 0L;
try
{
temp = new String(buf, "ISO8859_1");
}
catch(UnsupportedEncodingException _ex)
{
return;
}
start1 = temp.indexOf("filename");
temp = temp.substring(start1);
start3 = start1;
start1 = temp.indexOf(toke);
temp = temp.substring(start1 + 1);
start3 = start3 + start1 + 1;
start1 = temp.indexOf(toke);
String filename = temp.substring(0, start1);
filename = new String(filename.getBytes("ISO8859_1"));
FileOutputStream os;
try
{
File f1 = new File(workingpath + filename);
os = new FileOutputStream(f1);
}
catch(IOException _ex)
{
return;
}
start2 = temp.indexOf("stream");
start2 += 10;
start3 += start2;
FormSize -= start3;
KB *= 10;
buf = new byte[KB];
int iTimes = FormSize / KB;
int iMode = FormSize % KB;
is.mark(0);
is.reset();
is.skip(start3);
for(i = 0L; i < (long)iTimes; i++)
{
is.read(buf);
os.write(buf);
}

buf = new byte[iMode];
is.read(buf);
os.write(buf);
os.close();
ServletOutputStream out = res.getOutputStream();
out.println("");
}
}
...全文
130 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
rong1999 2004-08-08
  • 打赏
  • 举报
回复
是上传文件的servlet,不知道编译的CLASS在javascript 里是怎么用它?
foxty 2004-08-07
  • 打赏
  • 举报
回复
是一个上传文件的servlet吧?

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧