<Host appBase="D:\WebRoot\study" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">

 

[ 자동 리로드 ]

 

C:\tomcat-5.5.17\conf\Catalina\localhost\ROOT.xml

 

<Context path="" docBase="D:\WebRoot\study\ROOT" debug="0" reloadable="true" crossContext="true"/>

 

컨텍스트 이름별로 xml파일을 만든다.

 

[ 환경설정 ]

JAVA_HOME

CATALINA_HOME

CLASSPATH

import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;

 

public class CLASSNAME extends HttpServlet{

 

     public void init(ServletConfig config) throws ServletException {

          super.init(config);

     }

 

     public FUNCTION(){

          javax.servlet.ServletContext  servletContext  = getServletContext();

     }

}

 

ServletContext를 사용하기 위해선 init 메소드에서 super.init(config)를 해줘야한다.

(이유는 잘 모르겠다. 그에 답은 :http://okjsp.pe.kr/seq/40698)

 

ServletContext 객체를 얻을 수 있는 메서드는 HttpServlet 클래스의 getServletContext()이다.

(엄청 해깔린다. 이런식으로 ServletContext 의 servletContext 를 파라미터로 보내서 사용하면 좋을듯 싶다.

isELIgnored="false"         jstl 사용함

request.setCharacterEncoding("euc-kr");        한글 form 넘어온거

Properties 를 한번 사용할려고 여기저기, 자료를 찾을려고 기웃거려 봤는데..

워낙, 초보적인 내용이었는지.. 정리된것이 없더군요.


제가 가지고 있는 소스에 관련된 부분이 있어서.. 여기에 올립니다.

저초럼, 초보인 분에게 작은 도움이 될것 같아 올려봅니다.


......

간단히, 소스를 설명하자면..

PropertiesTest 실행할때

test.properties 라는 프로퍼티 파일을 가져오는데..

argument 가 있으면, test.properties 의 name 에 해당하는 value 를 불러오는거구요..

argument 가 없으면, test.properties 이의 프로퍼트에 value 을 변경시켜주는겁니다.~


test.properties 는 'PropertiesTest' class 가 있는 같은 디렉토리 위치에 있어야 겠지요.~


//===============================================================

//PropertiesTest.java
//===============================================================

import java.util.*;
import java.io.*;

class PropertiesTest {  

    public static void main(String[] args)  throws IOException   {
        Properties props = new Properties();
        if ( args.length == 0 )  {
            props.put("Name", "홍길동");
            props.put("Address", "Korea");
            props.store( new FileOutputStream("test.properties"), "My Comment");
        } else  {
            props.load( new FileInputStream("test.properties") );
        }

        System.out.println( "Name: " + props.getProperty("Name") );
        System.out.println( "Address: " + props.getProperty("Address") );
    }
}



//===============================================================

//test.properties

//===============================================================

#My Comment
Name=evergreen

Address=Korea

[Request  객체]

 

요청 피라미터 관련 메소드

 

String          getParameter(String name)                  피라미터의 값을 읽는다

String[]       getParameterValues(String name)        체크박스 같은 복수의 값을 배열로 읽는다

                  getRemoteAddr()                               아이피 얻기

                  request.setCharacterEncoding("euc-kr");          한글

 

 

HTTP 헤더 관련 메소드

 

String          getRemoteHost()                                클라이언드 이름 얻기

String          getRemoteAddr()                                클라이언트 IP주소 얻기

 

Date() -> String 타입

Date date1 = new Date();

String test = date1.toString();

 

 

날짜 변환 예제

<%@ page import = "java.text.DateFormat" %>
<%@ page import = "java.text.SimpleDateFormat" %>
<%@ page import = "java.util.Date" %>

 

Date date1 = new Date();
long time1 = date1.getTime();
long time2 = 1152393007234L;

 

// long 타입 시간을 문자열 날짜&시간으로 구하기

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
String strDate = df.format(time1);

 

// 문자열로 구해진 날짜&시간 Date() 타입으로 변경하기
DateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date birthDay = sdFormat.parse(strDate);

 

int(long) -> String 변환

Date nowDate = new Date();
long test = nowDate.getTime();

String test1 = Long.toString(test);  // int 일경우 Integer.

 

String  -> long 변환

long tet = Long.parseLong(long 타입 값);

 

파일 이동

File fileMove1 = new File(request.getRealPath("/") + "board/pds/" + fileName);
  File fileMove2 = new File(request.getRealPath("/") + "board/pds/" + tab + "/" + fileName);

  fileMove1.renameTo(fileMove2);

 

[ 올림/반올림/자름 ]

Math.ceil(double) 무조껀 올림

Math.floor(double) 무조껀 자름

Math.round(double) 반 올림

100 : Continue
101 : Switching protocols
200 : OK, 에러없이 전송 성공
201 : Created, POST 명령 실행 및 성공
202 : Accepted, 서버가 클라이언트 명령을 받음
203 : Non-authoritative information, 서버가 클라이언트 요구 중 일부 만 전송
204 : No content, 클라언트 요구을 처리했으나 전송할 데이터가 없음
205 : Reset content
206 : Partial content
300 : Multiple choices, 최근에 옮겨진 데이터를 요청
301 : Moved permanently, 요구한 데이터를 변경된 임시 URL에서 찾았음
302 : Moved temporarily, 요구한 데이터가 변경된 URL에 있음을 명시
303 : See other, 요구한 데이터를 변경하지 않았기 때문에 문제가 있음
304 : Not modified
305 : Use proxy
400 : Bad request, 클라이언트의 잘못된 요청으로 처리할 수 없음
401 : Unauthorized, 클라이언트의 인증 실패
402 : Payment required, 예약됨
403 : Forbidden, 접근이 거부된 문서를 요청함
404 : Not found, 문서를 찾을 수 없음
405 : Method not allowed, 리소스를 허용안함
406 : Not acceptable, 허용할 수 없음
407 : Proxy authentication required, 프록시 인증 필요
408 : Request timeout, 요청시간이 지남
409 : Conflict
410 : Gone, 영구적으로 사용할 수 없음
411 : Length required
412 : Precondition failed, 전체조건 실패
413 : Request entity too large,
414 : Request-URI too long, URL이 너무 김
415 : Unsupported media type
500 : Internal server error, 내부서버 오류(잘못된 스크립트 실행시)
501 : Not implemented, 클라이언트에서 서버가 수행할 수 없는 행동을 요구함
502 : Bad gateway, 서버의 과부하 상태
503 : Service unavailable, 외부 서비스가 죽었거나 현재 멈춤 상태
504 : Gateway timeout
505 : HTTP version not supported

+ Recent posts