±Û¾´ÀÌ :±è°Ç¿ì 2000³â 3¿ù 21ÀÏ 18:08:38
¼ºí¸´¿¡¼ ÈÀÏÀ» ºê¶ó¿ìÀú·Î º¸³»°í ½Í½À´Ï´Ù.
Áï ...../servlets/Download?num=3
À§¿Í °°Àº ½ÄÀ¸·Î ¼ºí¸´À» ½ÇÇà½ÃÅ°¸é ¼ºí¸´ÀÌ
ÇØ´ç ÈÀÏÀ» º¸³» ÁÖ´Â °ÍÀÔ´Ï´Ù. ¶ÇÇÑ Download¶õ
ÈÀϸíÀÌ ¾Æ´Ñ ¿øÇÏ´Â ÈÀϸíÀ¸·Î º¸³»ÁÖ¾î¾ß Çϱ¸¿ä
¾Æ·¡ Å×½ºÆ®¸¦ À§ÇÑ °£´ÜÇÑ ¼Ò½º¸¦ ¿Ã¸®°Ú½À´Ï´Ù.
ÀÌ´ë·Î ÇØ º¸´Ï test1234°¡ À̹ÌÁöÀÏ °æ¿ì´Â ºê¶ó¿ìÀú»ó¿¡
Ç¥½Ã°¡ µÇ´Âµ¥ ³ª¸ÓÁö´Â textÇüÅ·Π±×³É ȸ鿡 »Ñ·ÁÁö°í
´Ù¿î·Îµå´Â µÇÁö ¾Ê½À´Ï´Ù. ÀÎÅÍ³Ý ÀͽºÇ÷η¯ 4.0¿¡¼
Å×½ºÆ®Çß°í ¼¹ö´Â ¾ÆÆÄÄ¡ JServÀÔ´Ï´Ù.
ContentTypeÀ» text/plain»Ó¸¸ ¾Æ´Ï¶ó ´Ù¸¥°ÍÀ¸·Î ¹Ù²Ù¾îµµ
°á°ú´Â À§¿Í Ç×»ó °°°Ô ³ª¿É´Ï´Ù.
¾Æ½Ã´Â ºÐ ºÎµð µµ¿òÀ» Áֽñ⠹ٶø´Ï´Ù.
---- ¾Æ ·¡ ----
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Download extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
OutputStream out = res.getOutputStream();
res.setContentType("text/plain");
InputStream is = new FileInputStream("/home/httpd/servlets/test1234");
byte[] b = new byte[1024];
int count = 0;
while((count=is.read(b, 0, b.length))>0){
out.write(b, 0, count);
}
out.flush();
out.close();
}
}