Velocity 엔진 사용하기







 – velocity는 동적문서 생성, 동적 서블릿등에 사용할 수 있는 프레임 워크 임.



 jakarta 프로젝트에 포함되어 있는 velocity를 사용하기.



  try {
    
      Velocity.init(“velocity.properties”);          
     
  }catch(Exception e){


         e.printStackTrace();


  }
           
  VelocityContext context = new VelocityContext();
  context.put(“survey”, new Survey());        
  Template template =  null;
 


   try {


      template = Velocity.getTemplate(“template/survey.vm”, “EUC-KR”);
   } catch( Exception rnfe ){


      rnfe.printStackTrace();


   BufferedWriter writer = new BufferedWriter(out);


   try{
        if ( template != null)
            template.merge(context, writer);      
   }catch(Exception e){


        e.printStackTrace();


   }



  1. 위와 같은 형태로 사용된다.


  2. velocity.properties 파일을 적어준다.


    < 로그파일, 인코딩, 리소스로더등등이 포함된다. >



예제)velocity.properties 파일


runtime.log = velocity.log
output.ENCODING = EUC-KR
input.ENCODING = EUC-KR
resource.loader = file


file.resource.loader.description = Velocity File Resource Loader
file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
file.resource.loader.path = .


file.resource.loader.cache = false
file.resource.loader.modificationCheckInterval = 2


  주의) 리소스로더에대해 반드시 하나는 기술해줘야 한다. 리소스 로더 패스가 기술되지 않으면 getTemplate같은 리소스 관련 메소드를 실행시 에러가 남



답글 남기기

이메일 주소는 공개되지 않습니다.