자바 - include 관련

web 2007. 9. 28. 20:39

어제 c:import를 쓰면서 문득 생각난 것이 있었는데. jsp:include였다.

차이가 무엇일까 문서를 찾게 되었다.

 

c:import는 상대적인 URL, 외부 웹을 include하지만, jsp:include는 내부가 한계인듯 하다. (틀리면 알려주시요...)

 

밑에 발췌한 jsp:include는 relativeURL 나 표현식만을 page 어트리뷰트에 저장할 수 있다.

 

발췌

http://java.sun.com/products/jsp/syntax/1.2/syntaxref1214.html

 

 

<jsp:include>

Includes a static file or the result from another web component.

JSP Syntax

<jsp:include page="{relativeURL | <%= expression %>}" 	
   flush="true| false" />

or

<jsp:include page="{relativeURL | <%= expression %>}" 	
   flush="true| false" >	
   <jsp:param name="parameterName"	
      value="{parameterValue | <%= expression %>}" />+	
</jsp:include>

XML Syntax

<jsp:include page="{relativeURL | %= expression %}"	
   [ flush="true | false" ] /> 

or

<jsp:include page="{relativeURL | %= expression %}"	
[ flush="true | false" ] > 	
   [ <jsp:param name="parameterName" 	
      value="{parameterValue | %= expression %}" /> ] +	
</jsp:include> }

Examples

<jsp:include page="scripts/login.jsp" />
<jsp:include page="copyright.html" />
<jsp:include page="/index.html" />
<jsp:include page="scripts/login.jsp">	
   <jsp:param name="username" value="jsmith" />	
</jsp:include>

Description

The <jsp:include> element allows you to include either a static or dynamic resource in a JSP page. The results of including static and dynamic resources are quite different. If the resource is static, its content is included in the calling JSP page. If the resource is dynamic, it acts on a request and sends back a result that is included in the JSP page. When the include action is finished, the JSP container continues processing the remainder of the JSP page.

You cannot always determine from a pathname if a resource is static or dynamic. For example, http://server:8080/index.html might map to a servlet through a server alias. The <jsp:include> element handles both types of resources, so it is convenient to use when you don't know whether the resource is static or dynamic.

If the included resource is dynamic, you can use a <jsp:param> clause to pass the name and value of a parameter to the resource. As an example, you could pass the string username and a user's name to a login form that is coded in a JSP page.

Attributes

  • page="{ relativeURL | <%= expression %> }"

    The relative URL that locates the resource to be included, or an expression that evaluates to a String equivalent to the relative URL.

    The relative URL looks like a pathname--it cannot contain a protocol name, port number, or domain name. The URL can be absolute or relative to the current JSP page. If it is absolute (beginning with a /), the pathname is resolved by your web or application server.

  • flush="true | false"

    If the page output is buffered and the flush attribute is given a true value, the buffer is flushed prior to the inclusion, otherwise the buffer is not flushed. The default value for the flush attribute is false.

  • <jsp:param name="parameterName"
      value="{parameterValue | <%= expression %>}" />+ 

The <jsp:param> clause allows you to pass one or more name/value pairs as parameters to an included resource. The included resource should be dynamic, that is, a JSP page, servlet, or other resource that can process the parameter.

You can use more than one <jsp:param> clause if you want to send more than one parameter to the included resource. The name attribute specifies the parameter name and takes a case-sensitive literal string. The value attribute specifies the parameter value and takes either a case-sensitive literal string or an expression that is evaluated at request time.

 

 

발췌

http://aboutjsp.com/lec/include.jsp

 

 
* JSP Action - <jsp:include page="URI" flush="true" />

[syntax]
1). body 구문이 없는 경우
<jsp:include page="URI" flush="true" />

2). body 구문이 있는 경우
<jsp:include page="URI" flush="true">
<jsp:param name="파라메터이름" value="파라메터값" /> /* xxx.jsp?파라메터이름=파라메터값 */
</jsp:include>  

위와 같이 두가지 사용 용법이 있으며, 두번째 방법을 사용하면 해당 jsp파일에 파라메터값도 넘겨 줄수가 있습니다.
JSP Action 구문의 include 는 include되는 파일과 include 시키는 파일(doc1.jsp와 doc3.jsp)를 각각 컴파일 한후 두 파일의 실행 결과를 한곳에 합쳐서 출력을 하게 됩니다. 즉, 완전히 "별도로" 동작하게 됩니다.
여기에서 flush="true" 문장은 true나 false 가 들어 갈수 있는 부분으로써 include를 실행하기 전에 out.flush()를 실행할지 여부를 결정하는 것입니다. 물론 true일때 out.flush()를 실행하겠지요. JSP 스펙 1.1 까지는 반드시 true로 설정이 되어 있어야만 했으니, 1.2 부터는 true/false중 원하는것을 선택하면 됩니다.


* include 지시어 - <%@ include file="URI" %>

include 지시어 와 Action 구문과의 가장 큰 차이점은 include 지시어는 컴파일 되기전에 파일이 내용이 합쳐진다는 것입니다. 즉, doc3.jsp 는 doc2.jsp의 내용을 자신의 문서내에 포함하여 하나의 파일로 인식한다는 것입니다. doc2.jsp 에 보면 page Directive 가 생략이 되어 있는데, 그것이 바로 이러한 이유 때문입니다.

doc2.jsp에도 page Directive를 설정해 주었다면 에러가 발생할 것입니다. 하나의 페이지에 두번 선언을 하는 꼴이 되어 버릴테니까 말이죠.

 

그런데, Action 구문을 사용 하였을 때에는 두개의 파일 각각 다른 파일처리 되어 두개의 servlet 파일 생성하게 됩니다. 따라서 어느 한 파일이 수정되면 곧바로 적용되어 화면에 출력이 되게 됩니다.

하지만 include 지시어 문을 사용하게 되면 하나의 servlet 파일이 생성되게 됩니다. 이로 인해 엄청난 차이점이 발생하게 되는데, JSP의 특성상 JSP파일이 조금이라도 수정이 되어 있으면 servlet 으로 재 변경되어 다시 컴파일이 이루어 지게 됩니다. 그런데, doc2.jsp 파일을 내용을 수정하고, doc3.jsp 파일을 부르게 되면 수정되기 전의 doc2.jsp 파일의 내용이 출력됩니다.

 

이러한 특징은 tomcat 5 버젼대부터 달라지게 되었는데, include되는 파일을 수정하더라도 서블릿 컨테이너가 알아서 모두 재 컴파일 해준다는 것입니다. 필자가 확인한 바로는 OC4J 최신 버젼에서도 tomcat 5와 같이 자동으로 처리되었습니다.

 

 

 톰캣 5부터는 이러한 문제가 사라진다고 하는군... include에 대한 dependency를 제거된다고 한다.. 오호라~ 굿!

'web' 카테고리의 다른 글

L7 스위치 개념 및 동작원리  (0) 2007.09.29
L4스위치와 L7스위치의 차이점  (0) 2007.09.29
외부 컨텐츠를 가져오는 법  (0) 2007.09.28
jsp에서 한글이 깨지는 현상  (0) 2007.09.28
SSL (c, java)  (0) 2007.09.28
Posted by '김용환'
,

jsp에서 한글이 깨지는 것때문에 공부하게 되는 팁~~^^

이미 이런 jsp 베스트 프랙티스라 해서 사용하고 있는데...  굳이 코딩하거나 고민하지 않아도 된다는거....(살짝은 재미없다.)

그러나 나에게는 편하다라는 것~^^

 

 

발췌

JSP best practices: Import content to your Web site

http://www.ibm.com/developerworks/java/library/j-jsp06173.html

 

이 문서를 보면 다음과 같다.

 

 

Importing external content

One of the real advantages of using c:import is its ability to pull in content from external Web sites or Web applications. Back when you were learning about jsp:includes, you may have noticed that we used file attributes to designate static content to include. The file attribute does just what its name implies: it allows you to pull in a local file's content. The corresponding attribute for c:import is url, and it too does what its name suggests: it allows you to pull in any URL. Rather than just populating your site pages with content from local files, c:import lets you pull in content from any URL, which is essentially a really slick way to wrap content from other sites in your own look and feel.

Let's consider a simple example. Say I want to place some pictures of a gorgeous Madagascar Rosewood guitar on my Web site. While I could build my own page, complete with image files and relative links, it seems much easier to simply import the content from another site, then wrap it up in my site's look and feel. Listing 3 shows how easy it would be to use c:import's url attribute to pull in image files from my favorite guitar site:


Listing 3. Importing external content
<%@ page language="java" contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head>
     <title>newInstance.com</title>
     <meta http-equiv="Content-Type" 
       content="text/html; charset=iso-8859-1" />
     <link href="/styles/default.css" rel="stylesheet" type="text/css" />
</head>

<body>

<c:import url="header.jsp">
     <c:param name="pageTitle" 
       value="newInstance.com :: True North Guitars"/>
     <c:param name="pageSlogan" value="...building it from scratch" />
</c:import>
<%@ include file="/navigation.jsp" %>
<c:import url="bookshelf.jsp" />

<c:import 
  url="http://www.truenorthguitars.com/Clients/Richman/index.htm" />

<%@ include file="/footer.jsp" %>
</body>
</html>

The code looks good enough -- but if you try this out on your own, you'll quickly see a problem. None of the images show up and all of the relative links fail. Of course, if you think about it, the cause is perfectly clear. Because the external resource (in this case an image file) is interpreted, you get the result of that interpretation inserted directly into your output stream. External image links like /images/guitar-01-24.jpg will show up as missing. The only way to resolve this problem would be to copy the image to your site, which is an entirely different (and more time consuming) technique as compared to a simple import.

So importing external content really only makes sense if the content is purely text-based. For example, consider a site geared toward system administrators, with its own header, footer, and look and feel. One page of the site details how to set up an initial README file for users to see how the site should be used. You could refer to an existing FTP site's instructions as follows:

<c:import url="ftp://ftp.oreilly.com/pub/README.ftp" />

Notice that it's just as simple to import FTP server content as it is to pull in HTTP material. You can use the same command for HTTPS, as well as any other protocol that both your site and the target site understand and speak.

 

 

설명을 달면, c:import는 외부 웹싸이트 정보 또는 웹 어플리케이션의 컨텐츠를 가져올 수 있다고 한다.

 

<c:import url="bookshelf.jsp" />

<c:import
  url="http://www.truenorthguitars.com/Clients/Richman/index.htm" />

<c:import url="ftp://ftp.oreilly.com/pub/README.ftp" />

 

 

이렇게 다양하게 사용가능하다고 한다.

 

'web' 카테고리의 다른 글

L4스위치와 L7스위치의 차이점  (0) 2007.09.29
자바 - include 관련  (1) 2007.09.28
jsp에서 한글이 깨지는 현상  (0) 2007.09.28
SSL (c, java)  (0) 2007.09.28
아파치 래퍼럴 (apache referal)  (0) 2007.09.27
Posted by '김용환'
,

 

HTTPClient를 이용할때,  한글이 깨지는 현상이 있어서..

다음과 같이 처리했다.

 

Before

<%

 

 try {
    HttpClient client = new HttpClient();
   client.setTimeout(3000);
   GetMethod m = new GetMethod(content);
   int status = client.executeMethod(m);
   
   if (status == HttpStatus.SC_OK) {
      
    body = m.getResponseBodyAsString();
    m.releaseConnection();
    out.println("<base href="+dir+">");
    out.println(body);
   }
  }
  catch (Exception e) {
   System.out.println(e);
  }

%>

 

 

 

After

<%

String content = "";  

  if (url.indexOf("/community") != -1 ) {
   content = host + url;
  }
  else {
   content = host + "/static" + url;
  }

%>

 

<c:import url="${content}" charEncoding="MS949"/>

 

 

 

 

 

 

'web' 카테고리의 다른 글

자바 - include 관련  (1) 2007.09.28
외부 컨텐츠를 가져오는 법  (0) 2007.09.28
SSL (c, java)  (0) 2007.09.28
아파치 래퍼럴 (apache referal)  (0) 2007.09.27
외부싸이트에서 호출되는 것 확인하기  (0) 2007.09.22
Posted by '김용환'
,

SSL (c, java)

web 2007. 9. 28. 03:50

SSL 통신과 관련되어 좋은 정보가 있어서 소개한다.

c언어를 이용하여 SSL 통신을 java로 컨버팅한것이다. HTTPClient를 이용하면 굉장히 쉽게 사용할 수 있다.

 

c언어 공부용으로 발췌함~^^

 

출처

http://kldp.org/node/28194

 

 

서버(serv.c)

/* serv.cpp  -  Minimal ssleay server for Unix 
   30.9.1996, Sampo Kellomaki <sampo@iki.fi> */ 


/* mangled to work with SSLeay-0.9.0b and OpenSSL 0.9.2b 
   Simplified to be even more minimal 
   12/98 - 4/99 Wade Scholine <wades@mail.cybg.com> */ 

#include <stdio.h> 
#include <unistd.h> 
#include <stdlib.h> 
#include <memory.h> 
#include <errno.h> 
#include <sys/types.h> 
#include <sys/socket.h> 
#include <netinet/in.h> 
#include <arpa/inet.h> 
#include <netdb.h> 

#include <openssl/rsa.h>       /* SSLeay stuff */ 
#include <openssl/crypto.h> 
#include <openssl/x509.h> 
#include <openssl/pem.h> 
#include <openssl/ssl.h> 
#include <openssl/err.h> 


/* define HOME to be dir for key and cert files... */ 
#define HOME "./" 

/* Make these what you want for cert & key files */ 
#define CERTF  HOME "server-req.pem" 
#define KEYF  HOME  "server-key.pem" 


#define CHK_NULL(x) if ((x)==NULL) exit (1) 
#define CHK_ERR(err,s) if ((err)==-1) { perror(s); exit(1); } 
#define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(stderr); exit(2); } 

void main () 
{ 
    int err; 
    int listen_sd; 
    int sd; 
    struct sockaddr_in sa_serv; 
    struct sockaddr_in sa_cli; 
    size_t client_len; 

    SSL_CTX* ctx; 
    SSL*     ssl; 
    X509*    client_cert; 

    char*    str; 
    char     buf [4096]; 

    SSL_METHOD *meth; 

    /* SSL preliminaries. We keep the certificate and key with the context. */ 
    SSL_load_error_strings(); 
    SSLeay_add_ssl_algorithms(); 
    meth = TLSv1_server_method(); 

    // create a new SSL_CTX object as framework for TLS/SSL enabled functions 
    ctx = SSL_CTX_new (meth); 
    if (!ctx) { 
        ERR_print_errors_fp(stderr); 
        exit(2); 
    } 

    if (SSL_CTX_use_certificate_file(ctx, CERTF, SSL_FILETYPE_PEM) <= 0) { 
        ERR_print_errors_fp(stderr); 
        exit(3); 
    } 
    if (SSL_CTX_use_PrivateKey_file(ctx, KEYF, SSL_FILETYPE_PEM) <= 0) { 
        ERR_print_errors_fp(stderr); 
        exit(4); 
    } 
    if (!SSL_CTX_check_private_key(ctx)) { 
        fprintf(stderr,"Private key does not match the certificate public key\n"); 
        exit(5); 
    } 




    /* Prepare TCP socket for receiving connections */ 

    // Create Internet Socket and Fill sockaddr_in 
    listen_sd = socket (AF_INET, SOCK_STREAM, 0);    
    CHK_ERR(listen_sd, "socket"); 

    memset (&sa_serv, '\0', sizeof(sa_serv)); 
    sa_serv.sin_family      = AF_INET; 
    sa_serv.sin_addr.s_addr = INADDR_ANY; 
    sa_serv.sin_port        = htons (1111);          /* Server Port number */ 

    // Bind 
    err = bind(listen_sd, (struct sockaddr*) &sa_serv, sizeof (sa_serv));                    
    CHK_ERR(err, "bind"); 

    // Listening 
    err = listen (listen_sd, 5);  
    CHK_ERR(err, "listen"); 

    // Accept 
    client_len = sizeof(sa_cli); 
    sd = accept (listen_sd, (struct sockaddr*) &sa_cli, &client_len); 
    CHK_ERR(sd, "accept"); 

    // Close Listening socket 
    close (listen_sd); 

    // Connected-client info. 
    printf ("Connection from %lx, port %d\n", 
    sa_cli.sin_addr.s_addr, sa_cli.sin_port); 



    // TCP connection is ready. Do server side SSL. 
    // create a new SSL structure for a connection 
    ssl = SSL_new (ctx);                     
    CHK_NULL(ssl); 

    // connect the SSL object with a file descriptor 
    SSL_set_fd (ssl, sd); 
    err = SSL_accept (ssl);    
    CHK_SSL(err); 

    // Get the cipher - opt  
    printf ("SSL connection using %s\n", SSL_get_cipher (ssl)); 

    // Get client's certificate (note: beware of dynamic allocation) - opt 
    client_cert = SSL_get_peer_certificate (ssl); 
    if (client_cert != NULL)  
    { 
        printf ("Client certificate:\n"); 

        str = X509_NAME_oneline (X509_get_subject_name (client_cert), 0, 0); 
        CHK_NULL(str); 
        printf ("\t subject: %s\n", str); 
        free (str); 

        str = X509_NAME_oneline (X509_get_issuer_name  (client_cert), 0, 0); 
        CHK_NULL(str); 
        printf ("\t issuer: %s\n", str); 
        free (str); 

        /* We could do all sorts of certificate verification stuff here before 
           deallocating the certificate. */ 

        X509_free (client_cert); 
    }  
    else 
    { 
        printf ("Client does not have certificate.\n"); 
    } 

    // DATA EXCHANGE - Receive message and send reply. 
    err = SSL_read (ssl, buf, sizeof(buf) - 1);        
    CHK_SSL(err); 

    buf[err] = '\0'; 
    printf ("Got %d chars:'%s'\n", err, buf); 

    err = SSL_write (ssl, "I hear you.", strlen("I hear you.")); 
    CHK_SSL(err); 

    /* Clean up. */ 
    close (sd); 
    SSL_free (ssl); 
    SSL_CTX_free (ctx); 
} 

클라이언트(cli.c)

/* cli.cpp  -  Minimal ssleay client for Unix 
   30.9.1996, Sampo Kellomaki <sampo@iki.fi> */ 

/* mangled to work with SSLeay-0.9.0b and OpenSSL 0.9.2b 
   Simplified to be even more minimal 
   12/98 - 4/99 Wade Scholine <wades@mail.cybg.com> */ 

#include <stdio.h> 
#include <memory.h> 
#include <errno.h> 
#include <sys/types.h> 
#include <sys/socket.h> 
#include <netinet/in.h> 
#include <arpa/inet.h> 
#include <netdb.h> 

#include <unistd.h> 

#include <openssl/crypto.h> 
#include <openssl/x509.h> 
#include <openssl/pem.h> 
#include <openssl/ssl.h> 
#include <openssl/err.h> 


#define CHK_NULL(x) if ((x)==NULL) exit (1) 
#define CHK_ERR(err,s) if ((err)==-1) { perror(s); exit(1); } 
#define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(stderr); exit(2); } 

void print_x509(SSL *ssl) 
{ 
    char *ascii_cert; 
    X509 *cert = SSL_get_peer_certificate(ssl); 
    BIO *b; 
    BUF_MEM *bptr; 

    b = BIO_new(BIO_s_mem()); 

    if(X509_print(b, cert) > 0) 
    { 
        BIO_get_mem_ptr(b, &bptr); 
        ascii_cert = (char *)malloc(1 + bptr->length); 
        memcpy(ascii_cert, bptr->data, bptr->length); 
    } 
    else 
    { 
        ascii_cert = (char *)malloc(1024); 
        sprintf(ascii_cert, "This certificate has never been seen before and can't be shown\n"); 
    } 
    BIO_free(b); 

    /* X.509 인증서 출력 */ 
    printf("X.509:\n%s\n", ascii_cert); 
} 

void main (int argc, char **argv) 
{ 
    int err; 
    int sd; 
    struct sockaddr_in sa; 

    SSL_CTX* ctx; 
    SSL*     ssl; 
    X509*    server_cert; 

    char*    str; 
    char     buf [4096]; 
    char hello[80]; 

    SSL_METHOD *meth; 

    printf ("Message to send: "); 
    fgets (hello, 80, stdin); 

    SSLeay_add_ssl_algorithms(); 
    //meth = SSLv2_client_method(); 
    meth = TLSv1_client_method(); 
    SSL_load_error_strings(); 
    ctx = SSL_CTX_new (meth); 
    CHK_NULL(ctx); 
    CHK_SSL(err); 


    /////////////////////////////////////////////////////////////////////////////////////// 
    // Create a socket and connect to server using normal socket calls. 
    sd = socket (AF_INET, SOCK_STREAM, 0);   
    CHK_ERR(sd, "socket"); 

    memset (&sa, '\0', sizeof(sa)); 
    sa.sin_family      = AF_INET; 
    sa.sin_addr.s_addr = inet_addr ("203.247.40.139");   /* Server IP */ 
    sa.sin_port        = htons     (atoi(argv[1]));          /* Server Port number */ 

    // Normal-connect 
    err = connect(sd, (struct sockaddr*) &sa, sizeof(sa));      
    CHK_ERR(err, "connect"); 

    // Now we have TCP conncetion. Start SSL negotiation. 
    // create a new SSL structure for a connection 
    ssl = SSL_new (ctx);     
    CHK_NULL(ssl);     

    // connect the SSL object with a file descriptor 
    SSL_set_fd (ssl, sd); 

    // initiate the TLS/SSL handshake with an TLS/SSL server 
    err = SSL_connect (ssl);     
    CHK_SSL(err); 

    /*  
     * Following two steps are optional and not required for 
     * data exchange to be successful.  
     */ 

    printf ("SSL connection using %s\n", SSL_get_cipher (ssl)); 

    // Get server's certificate (note: beware of dynamic allocation) - opt  
    server_cert = SSL_get_peer_certificate (ssl);     
    CHK_NULL(server_cert); 
    print_x509(ssl); 

    /* 
    printf ("Server certificate:\n"); 
    str = X509_NAME_oneline (X509_get_subject_name (server_cert),0,0); 
    CHK_NULL(str); 
    printf ("\t subject: %s\n", str); 
    free (str); 

    str = X509_NAME_oneline (X509_get_issuer_name  (server_cert),0,0); 
    CHK_NULL(str); 
    printf ("\t issuer: %s\n", str); 
    free (str); 
    */ 

    /*  
     * We could do all sorts of certificate verification stuff here before 
     * deallocating the certificate.  
     */ 
    X509_free (server_cert); 

    /////////////////////////////////////////////////////////////////////////////////////// 
    // DATA EXCHANGE - Send a message and receive a reply. 
     
    //err = SSL_write (ssl, "Hello World!", strlen("Hello World!")); 
    //CHK_SSL(err);  
    err = SSL_write (ssl, hello, strlen(hello));   
    CHK_SSL(err); 

    err = SSL_read (ssl, buf, sizeof(buf) - 1);     
    CHK_SSL(err); 
    buf[err] = '\0'; 
    printf ("Got %d chars:'%s'\n", err, buf); 

    // send SSL/TLS close_notify 
    SSL_shutdown (ssl);   

    /* Clean up. */ 

    close (sd); 
    SSL_free (ssl); 
    SSL_CTX_free (ctx); 
} 

서버의 개인키와 셀프 사인된 인증서 입니다. 그리고 인증서의 패스워드는 abcd 입니다.

*server-key.pem

-----BEGIN RSA PRIVATE KEY----- 
Proc-Type: 4,ENCRYPTED 
DEK-Info: DES-EDE3-CBC,AA26BA50E01C1524 

oXXeC9GyPwvJxVyqRXROLXp5Ew5n/gS6+vpDXXSIsuE8RIk17Mtx1NpOGWxmQ/hd 
L9zAvDniOoavTyKyVI0VZx13A1RzptaSP1CqEBeQUlT5DU3IFhwdj8BRXfpaWrve 
NnCZiyvr5CNgSLg0pVvcUhI9CmQtj94bLN6KATbZ/FyQZTSkrN6kh1jBwHd04RvZ 
2YvxtuzevtxvLLHOvxCxocIYnPWJzViEyuKbz/co3ywZibFXrqu2Xpgrk3lHN21M 
ZXWPeVJ2DzAIWMhqjpOX98w0hLHvZHVWpiO09avH/wzR7YbCKZpwFZUdjcUuzETZ 
OzJO3p97mf9D64KbAOmq7h6Pme8pkT/io8Qe24XyaV0C7ca67t3J3NSBVmyPNgEP 
MsfTctk98FfKmOXD7fm1y5k4YZ7weDuDRs09KNFxn6sm94Q5ssQmaAPNCVZTpGSW 
p6/sDb1dU8/2lTFFU67tquwR679h2AouF/Ea0Sa2l0o8HfcAS8YJxp77+W2qB9Zt 
ymkSJlvX7s5qt4oBryTOyDKVFzmzksjJHaar7tRJ00fTh+AICxxQvfzUE82oH49R 
+07clHW7DCh4FMevvflSujfIChVIwvwg2Vr1b63QIp8tlZ0BiPAZH8TV6cPDROVQ 
5dWDQlcOrvfNsC1qI17kvn/N4ZzKyvdB4cEZh6xMH8UfFJ+qpNhJ1gwJFe9XI11z 
90hSa9lsFqBBw2sGmnN9QxKC1UpdvjoZV1VTBEqGWYDR4S1lx575gm77nF9XcJAr 
pW7Fs9qKLWi7trWQxI0ncKQ6DGuGbh/ctebgchKe/kIA/4E0nQjTcg== 
-----END RSA PRIVATE KEY----- 

*server-req.pem

-----BEGIN CERTIFICATE----- 
MIIDYjCCAsugAwIBAgIBADANBgkqhkiG9w0BAQQFADCBgzELMAkGA1UEBhMCQVUx 
EzARBgNVBAgTClNvbWUtU3RhdGUxDDAKBgNVBAcTA0ZvbzENMAsGA1UEChMETGFu 
ZDEMMAoGA1UECxMDRm9vMRYwFAYDVQQDEw1zbmFmdS5taXQuZWR1MRwwGgYJKoZI 
hvcNAQkBFg1mdWJvYkBtaXQuZWR1MB4XDTAwMTExMzAyMjgxMVoXDTAwMTIxMzAy 
MjgxMVowgYMxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMQwwCgYD 
VQQHEwNGb28xDTALBgNVBAoTBExhbmQxDDAKBgNVBAsTA0ZvbzEWMBQGA1UEAxMN 
c25hZnUubWl0LmVkdTEcMBoGCSqGSIb3DQEJARYNZnVib2JAbWl0LmVkdTCBnzAN 
BgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAtvnaO7XYscdlXoTwql5uHa5Vx1ecKZOc 
pSAqGQx4LnMGbRvnb+m2OxUZ3xFc8V1a2eKlUyTKoo0bebTeS5/BLBik47TjfUlw 
/P1hLYhIFZNb+o/g3ZeWG/9QZYs0favV+0iAoqpy/scHwHZg2Vnpjivsit543s+x 
uuWuD4fpUIsCAwEAAaOB4zCB4DAdBgNVHQ4EFgQUTkDDGu1osvRIZY/LlZdmRbAs 
rM0wgbAGA1UdIwSBqDCBpYAUTkDDGu1osvRIZY/LlZdmRbAsrM2hgYmkgYYwgYMx 
CzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMQwwCgYDVQQHEwNGb28x 
DTALBgNVBAoTBExhbmQxDDAKBgNVBAsTA0ZvbzEWMBQGA1UEAxMNc25hZnUubWl0 
LmVkdTEcMBoGCSqGSIb3DQEJARYNZnVib2JAbWl0LmVkdYIBADAMBgNVHRMEBTAD 
AQH/MA0GCSqGSIb3DQEBBAUAA4GBAEmPUSEShK6tHGdwPUvwYwp7cR0mwRNi3peB 
vu5nqwjCnCFaQaUdBfh/18kT5uEpGB48A/6BImov36Aiq9cq6dVNGQkVI0y/FJ0J 
28zSYrRHXGOS5qMoWRaqCabuYbDUsx/bvCr21ET948jMawdd8nq+3ungEQzlIZtO 
oWcmJYad 
-----END CERTIFICATE----- 

*컴파일

# gcc -o serv serv.c -lssl -lcrypto 
# gcc -o serv cli.c -lssl -lcrypto 

*실행

# ./serv 
Enter PEM pass phrase: abcd 

# ./cli 
Message to send: hello!! 

이번에는 자바 클라이언트 입니다.. 여기에서 에러가 나는데.. 봐주세요..^^;

*SunSSLSocketClient.java

import java.io.*; 
import java.net.*; 
import java.security.*; 
import javax.net.ssl.*; 

public class SunSSLSocketClient { 
    private static final String HOST = "127.0.0.1"; 
    private static final int    PORT = 1111; 
    private static String [] socketProtocolVersion = new String[] {"TLSv1"}; 

    public static void main(String [] args) throws Exception { 
        char [] passPhrase = "abcd1234".toCharArray(); 

        KeyStore keystore = KeyStore.getInstance("JKS"); 
        keystore.load(new FileInputStream(".keystore"), passPhrase); 

        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); 
        tmf.init(keystore); 

        SSLContext context = SSLContext.getInstance("TLS"); 
        TrustManager [] trustManagers = tmf.getTrustManagers(); 

        context.init(null, trustManagers, null); 

        SSLSocketFactory sf = context.getSocketFactory(); 
        SSLSocket socket = (SSLSocket)sf.createSocket(HOST, PORT); 
        socket.setEnabledProtocols(socketProtocolVersion); 
     
        System.out.println(socket); 

        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true); 
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream())); 

        pw.println("Hello!!"); 
        String fromServer = br.readLine(); 
        System.out.println(fromServer); 
    } 
} 

책에보니까 보통 이렇게 하더라구요.. 이렇게 코드를 작성하고 keytool을 사용해서 키저장소를 만들었습니다..
# keytool -genkey -keystore .keystore
.....

자바 클라이언트 실행
# java SunSSLSocketClient

Posted by '김용환'
,

jconsole

java core 2007. 9. 28. 03:44

 

jdk 5.0부터 새로 추가된 모니터링과 관련된 jconsole이라는 툴에 대한 내용은 다음의 주소를 참조한다.

 

 

http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html

Figure 1: Architecture of J2SE 5.0 Monitoring and Management Support.
 
 
Figure 3: MBeans Tab.
 
Figure 5: Memory Tab.
 
 
Posted by '김용환'
,

 

제일 잘 나온 내용이라 발췌~

 

 

출처

http://www.okjsp.pe.kr/seq/2035

 

delete,truncate,drop문의 비교.
DELETE, DROP, TRUNCATE의 비교
----------------------------------------------------------------

TABLE에서 행을 삭제하는 세 가지 OPTION의 비교

TABLE에서 모든 행을 삭제하는 방법에는 다음과 같은 세 가지 OPTION이 있다.

1. DELETE 명령어 사용

DELETE 명령어를 사용하여 TABLE의 행을 삭제할 수 있다.
예를 들어 EMP TABLE에서 모든 행을 삭제하는 명령문은 다음과 같다.

DELETE FROM emp;

O. DELETE 문을 사용할 때 TABLE이나 CLUSTER에 행이 많으면 행이 삭제 될 때마다 많은 SYSTEM 자원이 소모된다. 예를 들어 CPU 시간,REDO LOG 영역, TABLE이나 INDEX에 대한 ROLLBACK SEGMENT 영역 등의 자원이 필요하다.
O. TRIGGER가 걸려있다면 각 행이 삭제될 때 실행된다.
O. 이전에 할당되었던 영역은 삭제되어 빈 TABLE이나 CLUSTER에 그대로 남아 있게 된다.

2. DROP 과 CREATE 명령어 사용

TABLE을 삭제한 다음 재생성할 수 있다. 예를 들어 EMP TABLE을 삭제하고 재생성하는 명령문은 다음과 같다.

DROP TABLE emp;
CREATE TABLE emp (......);

O. TABLE이나 CLUSTER를 삭제하고 재생성하면 모든 관련된 INDEX, CONSTRAINT,TRIGGER도 삭제되며, 삭제된 TABLE이나 CLUSTERED TABLE에 종속된 OBJECTS는 무효화 된다.
O. 삭제된 TABLE이나 CLUSTERED TABLE에 부여된 권한도 삭제된다.

3. TRUNCATE 명령어 사용

SQL명령어 TRUNCATE를 사용하여 TABLE의 모든 행을 삭제할 수 있다.
예를 들어 EMP TABLE을 잘라내는 명령문은 다음과 같다.

TRUNCATE TABLE emp:

O. TRUNCATE 명령어는 TABLE이나 CLUSTER에서 모든 행을 삭제하는 빠르고 효율적인 방법이다.
O. TRUNCATE 명령어는 어떤 ROLLBACK 정보도 만들지 않고 즉시 COMMIT한다.
O. TRUNCATE 명령어는 DDL 명령문으로 ROLLBACK될 수 없다.
O. TRUNCATE 명령문은 잘라 버릴 TABLE과 관련된 구조(CONSTRAINT, TRIGGER 등)과 권한에 영향을 주지 않는다.
O. TRUNCATE 명령문은 현재 TABLE에 할당된 영역을 잘라버린 후에 포함되는 TABLESPACE로 복귀되도록 지정한다.
(REUSE STORAGE, DROP STORAGE OPTION 사용)
- DROP STORAGE OPTION 사용 시 : TABLE EXTENTS 수를 MINEXTENTS의 원래 설정값으로 줄인다.
해제된 확장영역은 SYSTEM에 복귀되며, 다른 OBJECTS가 사용할 수 있다.
- REUSE STORAGE OPTION 사용 시 : 현재 TABLE이나 CLUSTER에 할당된 모든 영역이 할당된 채로 남아 있도록 지정한다.
O. TRUNCATE 명령문이 TABLE에서 ROW를 삭제하면 해당 TABLE에 걸려 있는 TRIGGER는 실행되지 않는다.

O. AUDIT 기능이 ENABLE되어 있으면, TRUNCATE 명령문은 DELETE문에 해당하는 AUDIT 정보를 생성하지 않는다. 대신 발생한 TRUNCATE 명령문에 대한 단일 AUDIT RECORD를 생성한다.

* HASH CLUSTER는 잘라버릴 수 없다.

또한 HASH CLUSTER나 INDEX CLUSTER 내의 TABLE도 개별적으로 잘라버릴 수 없다.
INDEX CLUSTER를 잘라버리면 CLUSTER에 있는 모든 TABLE의 모든 ROW가 삭제된다.
모든 ROW가 각각의 CLUSTERED TABLE에서 삭제되어야 한다면 DELETE 명령어를 사용하거나 TABLE을 삭제하고 재생성한다.

from koug

laalaal~

Posted by '김용환'
,

첫인상의 힘

린다 골드맨 지음 | 나선숙 옮김
큰나무 2006.11.28
평점

 

첫인상의 중요성을 알린 책이다.

 

첫인상이 반을 먹으니, 옷차림이라던가, 말투를 잘 사용하라는 내용이다.

 

너무 요점을 비약했나? ^^

이 포스트를.. 파일로 저장

'After reading book' 카테고리의 다른 글

코칭의 힘  (0) 2007.10.27
가로세로 세계사 1  (0) 2007.10.03
2인자 리더쉽  (0) 2007.09.27
용기  (0) 2007.09.27
웃겨야 성공한다.(★★★)  (0) 2007.09.22
Posted by '김용환'
,

2인자 리더십

나채훈 지음
바움 2005.10.25
평점

인상깊은 구절
왜 2인자 리더십인가?
“뛰어난 2인자 없이 성공하는 1인자는 없다!”

삼국지를 보다보면, 현실의 정치와 어쩌면 똑같은지 감탄하지 않을 수 없다.

 

인간사중 유일하게 안바뀌는 게 있다면, 바로 정치인듯 싶다. 기술은 언제든지 바뀌고, 사람도 바뀌지만 이 정치라는 것은 그대로 인듯 싶다.

 

이 책은 겁나게 재미있다. 유비, 손권, 조조, 원소, 공손찬, 동탁과 같은 걸출한 인물의 얘기가 아니라 2인자를 추적한 책이다.

 

이런 측면의 책을 좋아하는데. 바로 Aspect 측면의 관점에서 보는 괜찮은 책이라 추천한다.

 

재미있는 것은 삼국지에 나온 2인자들이 모두 다른 특징을 가지고 있는 데, 각자 독특한 성격을 가지고 있다는 것이다.

일편단률적인 어떤 리더십이 아니라, 각각 상황에 맞는 리더십을 가지고 있다는 것인데..

 

 이 책에서 조명하고 있는 2인자들은 다양한 유형으로 분류된다. 즉 사마의처럼 1인자를 넘보는 자신의 야심을 가슴 깊숙이 감춘 채 행동한 승진추구형 2인자가 있는가 하면, 개혁과 올바른 세상을 위해 일한 2인자(저수, 제갈량, 노숙, 순욱, 진궁), 처음부터 동맹자로 가담한 2인자(주유, 장소, 순유), 1인자와의 혈연관계나 특이한 인연으로 봉사한 2인자(관우, 여몽, 가후, 육손)들도 있다. 특히 이 책에서 저자는 새로운 시대를 창출하려는 책사들의 창의성, 협력자로서의 의리, 리더의 덕목인 건강한 자아, 치밀한 현실 판단과 실천을 통해 성취감과 즐거움을 누리려고 노력한 2인자들의 진면목을 살피는 동시에 각각의 2인자들에게서 장단점을 찾아내어 2인자 리더십을 몸에 익히는 ‘행동 포인트’로 일목요연하게 정리해놓았다.

뱔췌 : http://book.naver.com/bookdb/book_detail.php?bid=1935741

 

순욱, 가후, 곽가, 사마의, 순유, 제갈량, 관우, 법정, 주유, 노숙, 여몽, 육손, 장소, 진궁, 저수의 인물을 보면서 삼국지를 즐겨보시라~

이 포스트를.. (+1)

'After reading book' 카테고리의 다른 글

가로세로 세계사 1  (0) 2007.10.03
첫 인상의 힘  (0) 2007.09.27
용기  (0) 2007.09.27
웃겨야 성공한다.(★★★)  (0) 2007.09.22
secret (★★★)  (0) 2007.09.22
Posted by '김용환'
,

용기

After reading book 2007. 9. 27. 21:28

용기

유영만 지음
위즈덤하우스 2007.03.29
평점

인상깊은 구절
모든 위대함은 작은 실천의 진지한 반복을 통해 서만 이루어진다. 언제나 우리 삶은 거창한 계획보다 작은 실천을 통해서 변화가 시작된다.

 

"모든 위대함은 작은 실천의 진지한 반복을 통해 서만 이루어진다. 언제나 우리 삶은 거창한 계획보다 작은 실천을 통해서 변화가 시작된다." - 용기

 

에반 얼마이어티에라는 영화를 보면, 이런 대사가 나온다.

에반 올마이티

감독 톰 새디악

출연 스티브 카렐,모간 프리먼

개봉 2007.07.25 미국, 95분

.

방주라는 뜻을 가진 ARK라는 단어를 땅바닥에 적으며 "acts of random kindness"에 비유한다.

 

나는 이렇게 말하고 싶다. 작지만 임의의 친절한 행복의 반복들이 큰 위대함을 낳는다.

 

이 책에서 주장하는 "삶을 바꾸는 7가지 용기"를 얘기하고자 한다.

 

1. 진퇴양난에 대사대성하라
오도 가도 못하는 어려운 상황에서도 크게 생각하고 크게 이루려는 용기가 필요합니다.

2. 백척간두에 즉행집완하라
높디높은 두려운 상황에서도 즉시 행동해서 완성하려는 용기가 필요합니다.

3. 누란지세에 백절불굴하라
계란을 쌓아올린 듯 긴장된 상황에서도 포기 대신 인내를 더하는 용기가 필요합니다.

4. 여리박빙에 불포가인하라
살얼음판 같은 아슬아슬한 상황에서도 포기 대신 인내를 더하는 용기가 필요합니다.

5. 설상가상에 초지일관하라
어려움이 가중되는 고통스런 상황에서도 처음의 열정을 되새기는 용기가 필요합니다.

6. 기호지세에 배수지진하라
호랑이 등에 올라탄 듯 긴박한 상황에서도 배수의 진을 치는 용기가 필요합니다.

7. 일촉즉발에 현존임명하라
언테 터질지 모르는 긴장된 상황에서도 현재의 모든 것을 거는 용기가 필요합니다.

 

이 포스트를.. (+1)

'After reading book' 카테고리의 다른 글

첫 인상의 힘  (0) 2007.09.27
2인자 리더쉽  (0) 2007.09.27
웃겨야 성공한다.(★★★)  (0) 2007.09.22
secret (★★★)  (0) 2007.09.22
Your best life now (★★★★★)  (0) 2007.09.21
Posted by '김용환'
,

 

머리만 쓴다면, DDOS 공격을 검색엔진을 통해서 할 수 있다.

아직까지 리포트된 것이 없지만, 오늘 급격한 리쿼스트를 확인해보니. 검색엔진으로부터의 요청이었다.

http request header의 refer 가 검색엔진이었다.

 

네이버

다음

파란

플래이포럼

msn검색

구글

 

이런 싸이트로부터 엄청난 공격이 시작되면 아파치에서 도메인이름을 가지고 필터링할 수 있다.

 

httpd.conf 파일이다.

 SetEnvIfNoCase Referer "http://(search\.)?naver\.com" link_denied
SetEnvIfNoCase Referer "http://(search\.)?empas\.com" link_denied
SetEnvIfNoCase Referer "http://(search\.)?daum\.net" link_denied
SetEnvIfNoCase Referer "http://(search\.)?playforum\.com" link_denied
SetEnvIfNoCase Referer "http://(dns\.)?paran\.com" link_denied
SetEnvIfNoCase Referer "http://kr\.search\.yahoo\.com" link_denied
SetEnvIfNoCase Referer "http://www5\.searchfun\.co\.kr" link_denied

 

<Directory ...>

      Order Deny,Allow
      Deny from  env=link_denied

</Directory>


 

 

특정 도메인으로부터 오는 DDOS 공격 또는 원치않은 검색은 다음과 같이 막을수도 있다.

 

이외 robot.txt 라 하여 검색엔진이 들어오지 못하도록 막을 수는 있다~

Posted by '김용환'
,