티스토리 툴바

달력

052012  이전 다음

  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  •  
  •  

'프로그래밍/JSP'에 해당되는 글 3건

  1. 2011/08/19 Log4j 설정하기
  2. 2011/06/24 [JDOM] XML Parsing (특정 Element 값 불러오기)
  3. 2011/06/10 Java TCP Server/Client Socket program (1)

< 설치 환경 >
Tomcat 7.0 : D:\Tomcat 7.0
WEB-INF : D:/workspace/WebContent/WEB-INF

(1) log4j-1.2.16.jar 파일을 Tomcat 경로의 lib 폴더에 저장.

 

 



(2) log4j.properies 의 파일을 WEB-INF/classes  에 저장.

로깅의 우선 순위에 따른 로깅 레벨이다.

FATAL > ERROR > WRN > INFO > DEBUG 

① FATAL : 가장 크리티컬한 에러가 일어 났을 때 사용합니다.
② ERROR : 일반 에러가 일어 났을 때 사용합니다.
③ WARN : 에러는 아니지만 주의할 필요가 있을 때 사용합니다.
④ INFO : 일반 정보를 나타낼 때 사용합니다.
⑤ DEBUG : 일반 정보를 상세히 나타낼 때 사용합니다.



 기타 참고 사이트
http://blog.naver.com/PostView.nhn?blogId=dalbong97&logNo=130021029647 

(log4j.properties)

 # 예제 : DEBUG ( login.java[doPost]:176) [2011-08-19 13:37:34,710] - MyTEST is GOOOOOOD!!!!
log4j.rootLogger = DEBUG, stdout, dailyfile
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p (%F[%M]:%L) [%d] - %m%n
log4j.appender.dailyfile.Threshold = DEBUG
log4j.appender.dailyfile = org.apache.log4j.DailyRollingFileAppender
log4j.appender.dailyfile.File = c:/was.log
log4j.appender.dailyfile.layout = org.apache.log4j.PatternLayout
log4j.appender.dailyfile.layout.ConversionPattern=%5p (%F[%M]:%L) [%d] - %m%n



(간략한 예제 소스) - Servlet
 import org.apache.log4j.Logger;

public class login extends HttpServlet {
 private static final long serialVersionUID = 1L;
 private static Logger logger = Logger.getLogger(login.class);  
 ....... (중략) ......

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
   logger.info("MyTEST is GOOOOOOD");
}

끝.

'프로그래밍 > JSP' 카테고리의 다른 글

Log4j 설정하기  (0) 2011/08/19
[JDOM] XML Parsing (특정 Element 값 불러오기)  (0) 2011/06/24
Java TCP Server/Client Socket program  (1) 2011/06/10
Posted by 불펭

1. JDOM 을 다운로드 (http://www.jdom.org)
2. jdom-1.1.1.zip 을 압출을 풀면 jdom.jar 파일이 있음.
3. jdom.jar 파일을 %CATALINA_HOME%lib  폴더 안에 복사 후 톰캣 리스타트!!

[적용 예제 소스는 첨부]

'프로그래밍 > JSP' 카테고리의 다른 글

Log4j 설정하기  (0) 2011/08/19
[JDOM] XML Parsing (특정 Element 값 불러오기)  (0) 2011/06/24
Java TCP Server/Client Socket program  (1) 2011/06/10
Posted by 불펭

 

In this example you'll see how to create a client-server socket communication. The example below consist of two main classes, the ServerSocketExample and the ClientSocketExample. The server application listen to port 7777 at the localhost. When we send a message from the client application the server receive the message and send a reply to the client application. The communication in this example using the TCP socket, it means that there is a fixed connection line between the client application and the server application.
package org.kodejava.example.net;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.ClassNotFoundException;
import java.lang.Runnable;
import java.lang.Thread;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerSocketExample {
    private ServerSocket server;
    private int port = 7777;

    public ServerSocketExample() {
        try {
            server = new ServerSocket(port);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        ServerSocketExample example = new ServerSocketExample();
        example.handleConnection();
    }

    public void handleConnection() {
        System.out.println("Waiting for client message...");

        //
        // The server do a loop here to accept all connection initiated by the
        // client application.
        //
        while (true) {
            try {
                Socket socket = server.accept();
                new ConnectionHandler(socket);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

class ConnectionHandler implements Runnable {
    private Socket socket;

    public ConnectionHandler(Socket socket) {
        this.socket = socket;

        Thread t = new Thread(this);
        t.start();
    }

    public void run() {
        try
        {
            //
            // Read a message sent by client application
            //
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
            String message = (String) ois.readObject();
            System.out.println("Message Received: " + message);

            //
            // Send a response information to the client application
            //
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
            oos.writeObject("Hi...");

            ois.close();
            oos.close();
            socket.close();

            System.out.println("Waiting for client message...");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

package org.kodejava.example.net;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.ClassNotFoundException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class ClientSocketExample {
    public static void main(String[] args) {
        try {
            //
            // Create a connection to the server socket on the server application
            //
            InetAddress host = InetAddress.getLocalHost();
            Socket socket = new Socket(host.getHostName(), 7777);

            //
            // Send a message to the client application
            //
            ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
            oos.writeObject("Hello There...");

            //
            // Read and display the response message sent by server application
            //
            ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
            String message = (String) ois.readObject();
            System.out.println("Message: " + message);

            ois.close();
            oos.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

[원문]http://www.kodejava.org/examples/216.html

'프로그래밍 > JSP' 카테고리의 다른 글

Log4j 설정하기  (0) 2011/08/19
[JDOM] XML Parsing (특정 Element 값 불러오기)  (0) 2011/06/24
Java TCP Server/Client Socket program  (1) 2011/06/10
Posted by 불펭