2012년 6월 21일 목요일

[jsp] img태그 src에 한글명 넣기(톰캣)



1. html
   <img src = "filedownload.jsp?filename=사진.jpg">




2. filedownload.jsp
-----------------------------------------------------------

<%@page contentType="text/html; charset=euc-kr" import ="java.io.*,java.text.*,java.util.*"%>


<%


String filename = new String(request.getParameter("filename").getBytes("ISO-8859-1"),"euc-kr");
String filename1 = java.net.URLEncoder.encode(filename, "UTF8");


System.out.println(filename);
System.out.println(filename1);


System.out.println("Request File Name:"+filename);
String appRoot = request.getRealPath("/");
System.out.println(appRoot);


File file = new File (appRoot+"/upload/"+filename);


System.out.println("DownLoad File:"+ file.getPath());


if(!file.exists()) {


%>


<script type="text/javascript">
alert("요청한 파일을 찾을 수 없습니다..");
history.back();
</script>
<%


  return;


}


BufferedInputStream input = null; 
BufferedOutputStream output = null;


response.reset();


String strClient = request.getHeader("User-Agent");
if (strClient.indexOf("MSIE 5.5") > -1) {  //익스  5.5
response.setContentType("application/x-msdownload"); 
response.setHeader("Accept-Ranges", "bytes");
response.setHeader("Content-Disposition", "filename=" + filename1 + ";"); 
response.setHeader("Content-Length", ""+ file.length());
   }else{           //익스 5.5이상
response.setContentType("application/x-msdownload"); 
response.setHeader("Content-Disposition", "attachment; filename=\""+filename1+"\";");
response.setHeader("Content-Transfer-Encoding", "binary;");
response.setHeader("Content-Length", ""+ file.length());
}


try {
input = new BufferedInputStream( new FileInputStream(file) ); 
byte buffer[] = new byte[1024];
int len = 0;
out.clear();
out.flush();
output = new BufferedOutputStream(response.getOutputStream());
while((len = input.read(buffer)) > 0 ){
output.write(buffer,0,len);
}
} catch(Exception e) {
e.printStackTrace();
System.out.println("File DownLoad Exception:" + e.getMessage());
} finally{
response.flushBuffer();
if(input !=null)try{input.close();}catch(Exception e){}
if(output !=null)try{output.close();}catch(Exception e){}
}
%>
-----------------------------------------------------------

2012년 6월 19일 화요일

[oracle] BLOB, CLOB 데이터 오라클에서 직접 INSERT


1. DIRECTORY로서 경로를 지정 (직접 디스크상에 존재하는 파일을 LOB에 넣어줘야 하니까.)
    단, 디렉토리를 만들기 위해서는 권한 필요
         GRANT CREATE ANY DIRECTORY TO user

-------------------------------------------------------------
CREATE OR REPLACE DIRECTORY CLOB_DIR
AS 'c:\';
-------------------------------------------------------------





2. PROCEDURE 생성(CLOB)

-------------------------------------------------------------
CREATE OR REPLACE PROCEDURE PCD_TBL_LOB_INSERT
(V_FILENAME IN VARCHAR2)
IS
    V_LOCATOR_CLOB  CLOB;
    
    V_SOURCE_DATA_FILE BFILE := BFILENAME('CLOB_DIR', V_FILENAME);    
    V_DEST_OFFSET    NUMBER := 1;
    V_SRC_OFFSET      NUMBER := 1;
    V_LANG_CONTEXT  NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
    V_WARNING           NUMBER;
    
BEGIN
         INSERT INTO TBL_LOB(NO, TXT_FILE)
         VALUES(SEQ_LOB.NEXTVAL, EMPTY_CLOB() )
         RETURNING TXT_FILE INTO V_LOCATOR_CLOB;
         
         DBMS_LOB.OPEN(V_SOURCE_DATA_FILE, 
                                  DBMS_LOB.LOB_READONLY);
                                  
         DBMS_LOB.LOADCLOBFROMFILE(V_LOCATOR_CLOB,
                                                      V_SOURCE_DATA_FILE,
                                                      DBMS_LOB.GETLENGTH(V_SOURCE_DATA_FILE),
                                                      V_DEST_OFFSET,
                                                      V_SRC_OFFSET,
                                                      DBMS_LOB.DEFAULT_CSID,
                                                      V_LANG_CONTEXT,
                                                      V_WARNING);
                                                      
         DBMS_LOB.CLOSE(V_SOURCE_DATA_FILE);
         
         COMMIT;
END;
 -------------------------------------------------------------
복잡해보이지만, 굵은 글씨로 된부분을 자신에게 맞게 고처주면된다.
EXEC PCD_TBL_LOB_INSERT('test.sql')

참고로 물리적 DIRECTORY 에서 지정된 공간에서 파일이 삭제되더라도 DB에는 파일이 남아있다.





3. PROCEDURE 생성(BLOB)

 -------------------------------------------------------------
CREATE OR REPLACE PROCEDURE PCD_TBL_BLOB_INSERT
(V_FILENAME IN VARCHAR2)
IS
    V_LOCATOR_BLOB  BLOB;
    
    V_SOURCE_DATA_FILE BFILE := BFILENAME('BLOB_DIR', V_FILENAME);
    
    V_DEST_OFFSET    NUMBER := 1;
    V_SRC_OFFSET      NUMBER := 1;
    
BEGIN
         INSERT INTO TBL_LOB2(NO, IMG_FILE)
         VALUES(SEQ_LOB.NEXTVAL, EMPTY_BLOB() )
         RETURNING IMG_FILE INTO V_LOCATOR_CLOB;
         
         DBMS_LOB.OPEN(V_SOURCE_DATA_FILE, 
                                  DBMS_LOB.LOB_READONLY);
                                  
         DBMS_LOB.LOADBLOBFROMFILE(V_LOCATOR_BLOB,
                                                      V_SOURCE_DATA_FILE,
                                                      DBMS_LOB.GETLENGTH(V_SOURCE_DATA_FILE),
                                                      V_DEST_OFFSET,
                                                      V_SRC_OFFSET,
                                                      );
                                                      
         DBMS_LOB.CLOSE(V_SOURCE_DATA_FILE);
         
         COMMIT;
         
         DBMS_OUTPUT.PUT_LINE('CLOB 타입 데이터 입력 성공!!!');
         
         EXCEPTION
            WHEN OTHERS THEN 
                DBMS_OUTPUT.PUT_LINE('CLOB 타입 데이터 입력 실패!!!');
END;
 -------------------------------------------------------------
EXEC PCD_TBL_BLOB_INSERT('저장할파일이름', 'dog.jpg');

SELECT *
FROM TBL_LOB2

2012년 6월 4일 월요일

[oracle] sysdba로 접속하기

CMD창 발췌!
----------------------------------------------------------------------
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\yj>sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on 화 6월 5 15:55:23 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

SQL> connect /as sysdba
연결되었습니다.
SQL>
----------------------------------------------------------------------

[oracle] Trigger 중지

* alter table 테이블명 disable all triggers;


* alter trigger 트리거명 disable