728x90
반응형
파일 다운로드에서...다운로드 받지 않고 바로 열려면...?

안녕하세요.

 

받을 파일은 전부 pdf 로 되어있습니다. 다운로드 로직을 이용해서 파일 전송이

완료되면 바로 아크로밧리더로 열리게 하고 싶습니다.

 

다운로드는 해당 파일의 고유 아이디를 가지고 서블릿을 호출해서

서블릿내의 로직이 돌아서 클라이언트로 해당 파일을 쏴 줍니다.

 

로직은 많이들 쓰고 있는 아래 로직인데요, 이게...바로 열리지 않고

다운로드 받는 창이 뜨던지 아니면 다운로드를 다 받은 후에 열리지 않고

블랭크 페이지로 표시됩니다.

 

    if (strClient.indexOf("MSIE 5.5") != -1) 
    { 
//     response.setContentType("Content-type: application/pdf;"); 
//     response.setHeader("Content-Disposition","attachment;filename="+fileName+";"); 
    } 
    else 
    { 
     response.setContentType("Content-type: application/pdf;"); 
//     response.setHeader("Content-Disposition",";filename="+fileName+";"); 
    }

 

위 쪽에 걸리면 다운로드 창이 뜨고, 아래쪽에 걸리면 자동으로 다운로드 받은 담에

블랭크페이지가 뜹니다...

 

조언 좀 부탁드립니다..

 

감사합니다.

 

     
Tag  
tag는 게시물의 성격을 나타내는 키워드를 입력하는 공간입니다. 
tag는 login 후 사용하실 수 있습니다.
  • 자문자답입니다.. 
    response.setContentType("Content-type: application/pdf;"); --> Content-type: 부분을 빼야하구.. 

    disposition-type 을 inline 으로 주면 되는군요
  • html
  •  
  • 2003-07-03 10:37:27
  • x
  • disposition-type 은 inline 과 attachment 가 있는데 inline 은 바로 여는 거구...attachment 는 선택의 기회(?)를 주는거라구 RFC1806 에 있군요..
  • html
  •  
  • 2003-07-03 10:39:27
  • x
728x90
반응형
728x90
반응형
mime type 입니다. 

MIME에서 제공하는 content-type에는 'text', 'image', 'audio', 'video', 'message', multipart', 'application'의 총 7가지가 존재하며 각 content-type마다 sub-type이 존재합니다.

Text의 sub-type으로는 'plaintext'와 'richtext'가 존재합니다. 
Image의 sub-type형태로는 'gif'포맷과 'jpeg'포맷이 존재합니다.
Audio의 sub-type으로는 'basic'이 있습니다. 
Video의 sub-type으로 'mpeg'이 존재합니다. 

Application 
액셀 화일이라든지, 파워 포인트 화일등을 표시 할수 있습니다.

Content-Type= text/plain에서 text/plain은 일반적인 평문의 글을 의미하며,html도 이에 해당 합니다.

첫번째줄의 내용은 MIME-Type
두번째줄의 내용은 어떤 화일인지 부연 설명
세번째중의 내용은 화일의 확장자 입니다.
참고 하세요. 
application/acad
AutoCAD drawing files
dwg

application/clariscad
ClarisCAD files
ccad

application/dxf
DXF (AutoCAD)
dxf

application/msaccess
Microsoft Access file
mdb

application/msword
Microsoft Word file
doc

application/octet-stream
Uninterpreted binary
bin

application/pdf
PDF (Adobe Acrobat)
pdf

application/postscript
PostScript, encapsulated PostScript,
Adobe Illustrator
ai, ps, eps

application/rtf
Rich Text Format file
rtf rtf

application/vnd.ms-excel
Microsoft Excel file
xls

application/vnd.ms-powerpoint
Microsoft PowerPoint file
ppt

application/x-cdf
Channel Definition Format file
cdf

application/x-csh
C-shell script
csh csh

application/x-dvi
TeX
dvi dvi dvi

application/x-javascript
JavaScript source file
js

application/x-latex
LaTeX source file
latex

application/x-mif
FrameMaker MIF format
mif

application/x-msexcel
Microsoft Excel file
xls

application/x-mspowerpoint
Microsoft PowerPoint file
ppt

application/x-tcl
TCL script
tcl

application/x-tex
TeX source file
tex

application/x-texinfo
Texinfo (emacs)
texinfo, texi 

application/x-troff
troff file
t, tr, roff t, tr, roff

application/x-troff-man
troff with MAN macros
man 

application/x-troff-me
troff with ME macros
me

application/x-troff-ms
troff with MS macros
ms

application/x-wais-source
WAIS source file
src

application/zip
ZIP archive
zip

audio/basic
Basic audio (usually m-law)
au, snd

audio/x-aiff
AIFF audio
aif, aiff, aifc

audio/x-wav
Windows WAVE audio
wav 

image/gif
GIF image
gif

image/ief
Image Exchange Format file
ief

image/jpeg
JPEG image
jpeg, jpg jpe 

image/tiff
TIFF image
tiff, tif

image/x-cmu-raster
CMU Raster image
ras

image/x-portable-anymap
PBM Anymap image format
pnm

image/x-portable-bitmap
PBM Bitmap image format
pbm

image/x-portable-graymap
PBM Graymap image format
pgm

image/x-portable-pixmap
PBM Pixmap image format
ppm

image/x-rgb
RGB image format
rgb

image/x-xbitmap
X Bitmap image
xbm

image/x-xpixmap
X Pixmap image
xpm

image/x-xwindowdump
X Windows Dump (xwd) 
xwd

multipart/x-gzip
GNU ZIP archive
gzip

multipart/x-zip
PKZIP archive
zip

text/css
Cascading style sheet 
css

text/html
HTML file
html, htm

text/plain
Plain text
txt 

text/richtext
MIME Rich Text
rtx

text/tab-separated- values
Text with tab-separated values
tsv

text/xml
XML document
xml

text/x-setext
Struct-Enhanced text 
etx

text/xsl
XSL style sheet
xsl

video/mpeg
MPEG video
mpeg, mpg, mpe 

video/quicktime
QuickTime video
qt, mov

video/x-msvideo
Microsoft Windows video
avi

video/x-sgi-movie
SGI movie player format
movie
728x90
반응형
728x90
반응형
#!/bin/bash
##########################################################################
# File Upload BATCH   PROGRAM
#
# 2009.02.09
#
#     make by LEE TAE YOUNG
##########################################################################

#-------------------------------------------------------------------------
# java export
#-------------------------------------------------------------------------
echo "========================= clover plaza File Upload batch start ======================"
echo " start time : `date`"

export JAVA_HOME=/usr/local/java
export JAVA_BIN=$JAVA_HOME/bin
export JAVA_LIB=$JAVA_HOME/lib
export TOMCAT_HOME=/usr/local/apache-tomcat-6.0.18
export PATH=.:$JAVA_BIN:$PATH
export PRJ_HOME=$TOMCAT_HOME/webapps/ROOT
#export PRJ_HOME=/export/home/tylee/clover/CLOVER_click

CLASSPATH=$CLASSPATH:$PRJ_HOME/WEB-INF/lib/ibatis-2.3.0.677.jar; export CLASSPATH
CLASSPATH=$CLASSPATH:$PRJ_HOME/WEB-INF/lib/ibatis-common-2.jar; export CLASSPATH
CLASSPATH=$CLASSPATH:$PRJ_HOME/WEB-INF/lib/ibatis-dao-2.jar; export CLASSPATH
CLASSPATH=$CLASSPATH:$PRJ_HOME/WEB-INF/lib/ibatis-sqlmap-2.jar; export CLASSPATH
CLASSPATH=$CLASSPATH:$PRJ_HOME/WEB-INF/lib/NetComponents-1.3.8.jar; export CLASSPATH
CLASSPATH=$CLASSPATH:$PRJ_HOME/WEB-INF/lib/postgresql-8.1-405.jdbc3.jar; export CLASSPATH
CLASSPATH=$CLASSPATH:$PRJ_HOME/WEB-INF/lib/log4j-1.2.15.jar; export CLASSPATH

CLASSPATH=$CLASSPATH:$PRJ_HOME/WEB-INF/lib/commons-logging.jar; export CLASSPATH
CLASSPATH=$CLASSPATH:$PRJ_HOME/WEB-INF/lib/jce-jdk13-119.jar; export CLASSPATH
CLASSPATH=$CLASSPATH:$PRJ_HOME/WEB-INF/lib/xercesImpl.jar; export CLASSPATH
CLASSPATH=$CLASSPATH:$PRJ_HOME/WEB-INF/lib/xmlParserAPIs.jar; export CLASSPATH
CLASSPATH=$CLASSPATH:$PRJ_HOME/WEB-INF/lib/j2ssh.jar; export CLASSPATH
export CLASSPATH=.:$CLASSPATH

cd $TOMCAT_HOME/webapps/ROOT/WEB-INF/classes

#-------------------------------------------------------------------------
# java excute
#-------------------------------------------------------------------------

BATCHPROPERTIES=batch.properties
ERROR=0

java -Dfile.encoding=UTF-8 jp.or.cloverplaza.batch.FileUploadBatch $BATCHPROPERTIES >> $TOMCAT_HOME/clover_logs/batch/batch_FileUpload_$(date +%Y%m%d).log

ERROR=$?

exit $ERROR

echo " end time : `date`"
echo "========================= clover plaza File Upload batch end ======================="
728x90
반응형
728x90
반응형

//NetComponents-1.3.8 (http://www.savarese.org/downloads/NetComponents/)  라이브러리 필요

import java.io.IOException;
import java.io.PrintWriter;

import com.oroinc.net.ftp.FTP;
import com.oroinc.net.ftp.FTPClient;
import com.oroinc.net.ftp.FTPConnectionClosedException;
import com.oroinc.net.ftp.FTPReply;

public class FtpManager {

    protected static FTPClient ftp;

    protected static boolean FTPConnect(String server, String username, String password){
        ftp = new FTPClient();
        ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

        try {
              int reply;
              ftp.connect(server);
              System.out.println("Connected to " + server + ".");

              // After connection attempt, you should check the reply code to verify
              // success.
              reply = ftp.getReplyCode();

              if(!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.out.println("FTP server refused connection.");
                return false;
              }

            //Login FTP
            if(!ftp.login(username, password)) {
                ftp.logout();
                return false;
            }

            System.out.println("Remote system is " + ftp.getSystemName());

            //Setting BINARY method
            ftp.setFileType(FTP.BINARY_FILE_TYPE);

        }catch(FTPConnectionClosedException e) {
            System.out.println("Server closed connection.");
            e.printStackTrace();
            return false;
        } catch(IOException e) {
            if(ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch(IOException f) {
                    //do nothing
                }
            }
            System.out.println("Could not connect to server.");
            e.printStackTrace();
            return false;
        }

        return true;
    }

    protected static boolean FTPConnect(String server, int port, String username, String password){
        ftp = new FTPClient();
        ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

        try {
              int reply;
              ftp.connect(server, port);
              System.out.println("Connected to " + server + ":" + port);

              // After connection attempt, you should check the reply code to verify
              // success.
              reply = ftp.getReplyCode();

              if(!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                System.out.println("FTP server refused connection.");
                return false;
              }

            //Login FTP
            if(!ftp.login(username, password)) {
                ftp.logout();
                return false;
            }

            System.out.println("Remote system is " + ftp.getSystemName());

            //Setting BINARY method
            ftp.setFileType(FTP.BINARY_FILE_TYPE);

        }catch(FTPConnectionClosedException e) {
            System.out.println("Server closed connection.");
            e.printStackTrace();
            return false;
        } catch(IOException e) {
            if(ftp.isConnected()) {
                try {
                    ftp.disconnect();
                } catch(IOException f) {
                    //do nothing
                }
            }
            System.out.println("Could not connect to server.");
            e.printStackTrace();
            return false;
        }

        return true;
    }


    public static void FTPDisconnect(){
        if(ftp.isConnected()) {
            try {
                ftp.disconnect();
                System.out.println("Disconnect to server.");
            } catch(IOException f) {
                // do nothing
                System.out.println("Disconnect Error. : " + f.getMessage());
                f.printStackTrace();
            }
        }
    }

}
728x90
반응형
728x90
반응형
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

public class ReadProperties {
    public static Properties getInfo(String path){
        Properties batchProps = new Properties();
        try
        {
            InputStream is =
                    new FileInputStream(path);
            batchProps.load(is);
        }
        catch (Exception e)
        {
            System.out.println("Error. : Can't read the config.properties file.");
            return null;
        }
        
        return batchProps;
    }
}
728x90
반응형
728x90
반응형
SFTP 를 사용하기 위한 소스...
라이브러리는 j2ssh-0.2.9-src(http://sourceforge.net/projects/sshtools/(%20j2ssh))를 직접 jar로 만들어 사용...

import com.sshtools.j2ssh.SftpClient;
import com.sshtools.j2ssh.SshClient;
import com.sshtools.j2ssh.authentication.AuthenticationProtocolState;
import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient;
public class J2sshSftpCient 
{
    private SshClient client = null;
    private PasswordAuthenticationClient auth = null;
    private SftpClient sftp = null;
    
    public J2sshSftpCient(String server, String user, String pwd) throws Exception
    {
        try {
            if (server == null || user == null || pwd == null) {
                System.out.println("Parameter is null!");
            }
            client = new SshClient();
            client.setSocketTimeout(70000);
            client.connect(server);

            auth = new PasswordAuthenticationClient();
            auth.setUsername(user);
            auth.setPassword(pwd);
            int result = client.authenticate(auth);
            if (result != AuthenticationProtocolState.COMPLETE) {
                 throw new Exception("Login to " + server + ":22" + 
                      user + "/" + pwd + " failed");
            }
            sftp = client.openSftpClient();
        } catch (Exception e) {
            System.out.println(e);
            throw e;          
        }
    }
    
    public boolean put(String path) throws Exception
    {
        boolean rtn = false;
        try    {
            if (sftp != null) {
                sftp.put(path);
                rtn = true;
            }
        } catch(Exception e) {
            System.out.println(e);
        }
        return rtn;
    }
    
    public boolean get(String srcFile, String destFile) throws Exception
    {
        boolean rtn = false;
        try {
            if (sftp != null) {
                if (destFile == null)
                    sftp.get(srcFile);
                else
                    sftp.get(srcFile, destFile);
                rtn = true;
            }
        } catch(Exception e) {
            System.out.println(e);
        }
        return rtn;
    }
    
    public boolean lcd(String path) throws Exception
    {
        boolean rtn = false;
        try {
            if (sftp != null) {
                sftp.lcd(path);
                rtn = true;
            }
        } catch(Exception e) {
            System.out.println(e);
        }
        return rtn;
    }
    
    public boolean cd(String path) throws Exception
    {
        boolean rtn = false;
        try {
            if (sftp != null) {
                sftp.cd(path);
                rtn = true;
            }
        } catch(Exception e) {
            System.out.println(e);
        }
        return rtn;
    }
    
    public String pwd() throws Exception
    {
        String rtnStr = null;
        try {
            if (sftp != null) {
                rtnStr = sftp.pwd();
            }
        } catch(Exception e) {
            System.out.println(e);
        }
        return rtnStr;
    }
    
    public boolean chmod(int permissions, String path) throws Exception
    {
        boolean rtn = false;
        try {
            if (sftp != null) {
                sftp.chmod(permissions, path);
                rtn = true;
            }
        } catch(Exception e) {
            System.out.println(e);
        }
        return rtn;
    }
    
    public boolean rm(String path) throws Exception
    {
        boolean rtn = false;
        try {
            if (sftp != null) {
                sftp.rm(path);
                rtn = true;
            }
        } catch(Exception e) {
            System.out.println(e);
        }
        return rtn;
    }

    public boolean isClosed() throws Exception
    {
        boolean rtn = false;
        try {
            if (sftp != null)
                rtn = sftp.isClosed();
        } catch(Exception e) {
            System.out.println(e);
        }
        return rtn;
    }
    
    public boolean logout() throws Exception
    {
        boolean rtn = false;
        try {
            if (sftp != null)
                sftp.quit();
            if (client != null)
                client.disconnect();
            rtn = true;
        } catch(Exception e) {
            System.out.println(e);
        }
        return rtn;
    }
}

728x90
반응형
728x90
반응형

간단하게 사용하자..복잡한건 싫으니...ㅋㅋㅋ


   FileReader fr = new FileReader( new File("C\test.csv");
   BufferedReader br = new BufferedReader( fr );

   String csvStr = "";
   String tmpStr = "";
   while(tmpStr != null)
   {
    tmpStr = br.readLine(); //한 라인씩 읽어 들임
    System.out.println("!!!!!!!!!tmpStr = " + tmpStr);
    if(tmpStr != null)
    {
     csvStr = csvStr + tmpStr + "||";
    }
   }
   
   System.out.println("#########csvStr = \n" + csvStr + "\n##################");
   

728x90
반응형
728x90
반응형

자바 프로젝트에서 데이터베이스를 postgreSQL을 이용하는 경우, JDBC를 새로 받는다.

다운로드 사이트 : [http://jdbc.postgresql.org]

JDBC를 이용하여 데이터베이스에 연결하는 방법 예제...

import java.sql.*;
public class Untitled1 {

  public Untitled1() {
  }

  public void test() {

    try {
      String url = "jdbc:postgresql://localhost/mydb";
      String user = "Administrator";
      String password = "000000";

      Class.forName("org.postgresql.Driver");

      Connection con = DriverManager.getConnection(url, user, password);
      Statement stmt = con.createStatement();
      ResultSet rset = stmt.executeQuery(" select city from weather ");

      System.out.println("결과 ==>> ");

      if(!rset.next()) {
        System.out.println("Nothing!");
      } else {
        String show = rset.getString(1);
        System.out.println("->> "+show);
      }

      if(rset != null) rset.close();
      if(stmt != null) stmt.close();
      if(con != null) con.close();
    } catch(Exception e) {
      System.out.println(e.getMessage());
    }

  }
  public static void main(String[] args)  throws Exception {
    Untitled1 untitled11 = new Untitled1();
    untitled11.test();
  }
}


728x90
반응형

+ Recent posts