用SERVLETS实现WEB方式的文件下传
类别: JSP教程
// Download.java
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
/**
* The simplest download servlet.
*
* @author Huang Jian-chang
*/
public class Download extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType( "application/doc" ); // MIME type for pdf doc
response.setHeader("Content-disposition",
"attachment; filename=" +
"table.doc" );
String fileURL = "http://hjc/table.doc";
URL url=new URL(fileURL);
BufferedInputStream bis = new BufferedInputStream(url.openStream());
BufferedOutputStream bos = new BufferedOutputStream( response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1!=(bytesRead=(bis.read(buff,0,buff.length)))){
bos.write(buff,0,bytesRead);
}
if (bis!=null){
bis.close();
}
if (bos!=null){
bos.close();
}
}
}
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
/**
* The simplest download servlet.
*
* @author Huang Jian-chang
*/
public class Download extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType( "application/doc" ); // MIME type for pdf doc
response.setHeader("Content-disposition",
"attachment; filename=" +
"table.doc" );
String fileURL = "http://hjc/table.doc";
URL url=new URL(fileURL);
BufferedInputStream bis = new BufferedInputStream(url.openStream());
BufferedOutputStream bos = new BufferedOutputStream( response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1!=(bytesRead=(bis.read(buff,0,buff.length)))){
bos.write(buff,0,bytesRead);
}
if (bis!=null){
bis.close();
}
if (bos!=null){
bos.close();
}
}
}
- 上一篇: 头文件生成器-JAVAH.EXE
- 下一篇: 怎样制作自解压的JAR文件
-= 资 源 教 程 =-
文 章 搜 索