[급 요청] 파일다운로드(오라클->웹)

kor2u의 이미지

oracle.jdbc.driver.OracleBlobInputStream의 타입으로 데이터를 down.jsp로 가지고 왔는데..
파일을 다운로드 하면 빈공백만 있습니다.

제가 하고자 하는 것은 디비에 저장되어있는 blob형태의 데이터(ppt, doc, hwp 등)를 파일서버가
아닌 디비에서 바로 가져와서 웹상에서 다운로드 되게 하고 싶거든요.

좀 도와주세요;;

소스는 아래와 같습니다.

// FileManager를 통해서 Item으로 filename과 filedat를 가져옵니다.
// 여기서 filename은 String이고 filedat는 InputStream 타입입니다.

File.FileItem Item = FileManager.get(conn, id, seqno);

String fileName = "";
fileName = Item.fileName;

response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename=\""+fileName+"\"");

InputStream in = Item.fileDat;
OutputStream os = response.getOutputStream();

byte[] buffer = new byte[1024*1024*5];
int n = -1;

while((n = in.read(buffer)) != -1){
os.write(buffer, 0, n);
}

in.close();
os.close();

cleol의 이미지

코드만 보고는 알 수 없을 것 같습니다. 우선 예외가 발생한 것은 없는지 로그 파일을 확인하시구요. 어떤 환경에서 작업하시는지 모르겠는데, IDE 에서 디버깅 모드로 실행하실 수 있으면 while 루프를 한 스텝씩 트레이스하시면서 실제로 데이터를 스트림에 출력하는 과정을 살펴보세요. 디버깅 모드로 실행하실 수 없다면 while 루프 안에서 몇 바이트를 읽어서 쓰는지 System.out.println(n) 으로 찍어보시구요. (사용하시는 어플리케이션 서버에 따라 다를텐데 표준출력을 기록하는 로그 파일이 있을겁니다.) 혹시나 while 루프를 한 번도 안 돈다거나 하면 DB에 데이터가 제대로 저장되어 있지 않을 가능성이 큽니다.

M.W.Park의 이미지

apache tomcat에서 jsp를 쓴건가요?
예전 기억이지만, tomcat의 jsp 페이지에서는 content가 html이 아니면 잘 안됐던 것같습니다.
맨앞에 줄바꿈이 4개인가 정도 들어갔던가 어쨌던가 (가물가물) 그래서 간단히 jsp로 하려던 것을 servlet으로 만든 적이 있습니다. (저는 xml + xsl을 바로 브라우저로 보내려고했는데... 첫줄이 <xml ...>로 시작 안한다고 불평하면서 제대로 페이지를 렌더링 못하는 브라우저가 있었습니다.)
결론은 servlet으로 한번 시도해보시는 것이 좋을듯합니다만....

좀 오래된 이야기이니 지금은 아닐 수도.... (도망갈 구멍 마련... ^^)

-----
오늘 나의 취미는 끝없는, 끝없는 인내다. 1973 法頂

-----
오늘 의 취미는 끝없는, 끝없는 인내다. 1973 法頂

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.