jsp에서 db에 저장된 내용을 마치 파일처럼 사용할려면 어떻게

moonrepeat의 이미지

현재 jsp를 이용해서 뭔가를 만들고 있는데
데이터 베이스에 바이너리 파일을 저장하는 것 까지는 했습니다.
그런데 이놈을 빼내오지를 못하겠습니다.

즉 db에는 css와 jpg 그리고 hwp 파일이 저장되어 있습니데
이놈들을 마치 파일이 있는 것처럼 빼내오는 방법을 좀 알고 싶습
니다.

참고될 만한 사이트나 힌트등을 알려주시면 감사하겠습니다.

mach의 이미지

blob java로 검색해도 안나오나요?

------------------ P.S. --------------
지식은 오픈해서 검증받아야 산지식이된다고 동네 아저씨가 그러더라.

moonrepeat의 이미지

다시 질문 올립니다.

환경 : JDBC(2.0) + MS-SQL2000(SP4) + IIS + Tomcat(5.0)

이미지파일을 binary로 DB(image type)에 저장했고, 이제 이 데이터를 JSP로 불러내서
클라이언트측으로 가져오려고 합니다.

질문1) JSP를 이용해서 DB의 이미지 데이터를 클라이언트에 HTML로 바로 보여줄 수 있는 방법이 있나요?
(PHP에서는 가능한 것 같은데, JSP는 어떻게 하는지 모르겠군요..)

질문2) DB 데이터를 스트림으로 받아서 클라이언트에 파일로 다운로드하고 싶은데, 소스는 다음과 같습니다.
이렇게 하면, [SQLServer 2000 Driver for JDBC]Object has been closed. 라는 에러메세지가 뜹니다.
제 생각에는 fi.read() 할 때 에러가 나는거 같은데, 뭐가 틀렸는지는 모르겠군요.
고수님들의 답변 부탁드립니다. :D

<%@ page contentType="application/x-msdownload; charset=EUC_KR" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
<%@ include file = "/../connect.jsp" %>  // connection 부분, statement까지 선언되어 있습니다.
<%
	InputStream fi = null;
	String SQL="select ID,IMG,length from testimg where ID=003";
	ResultSet rs = stmt.executeQuery(SQL); 
	rs.next();
	String filename = rs.getString("ID") + ".jpg";
	fi=rs.getBinaryStream("IMG");
	int length = rs.getInt("length");

	response.setHeader("Content-Disposition","attachment; filename="+filename);	//Content-Disposition 헤더에 파일 이름 세팅.

	OutputStream outStream = response.getOutputStream();
	byte buf[] = new byte[4096];
	while(true)
	{
        	int readBytes = fi.read(buf);
        	if( readBytes < 0)
	        	break;
	        outStream.write(buf,0, readBytes);
	}
	outStream.flush();

	fi.close();
	outStream.close();

%>

삽질은 계속되어야 한다....... 쭉.........

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.