달력

32024  이전 다음

  • 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

벨로시티에서 제공하는 툴들은 여러 종류가 있다.

GenericTools
VelocityView
VelocityStruts

이 있는데... 간단하게 GenericTools 에 있는 DateTool 을 사용해봤다.

http://jakarta.apache.org/velocity/tools/generic/

요기 GenericTools 를 볼 수 있당.

사용법은 무지 간단..

먼저 Tool 을 사용하기 위해..  toolbox.xml 을 WEB-INF/ 디렉토리에 생성하고,
VelocityViewServlet 에 해당 툴을 등록시켜주면 된다.

=============================================
<?xml version="1.0" encoding="UTF-8"?>

<toolbox>

  <tool>
    <key>date</key>
 <scope>application</scope>
 <class>org.apache.velocity.tools.generic.DateTool</class>
  </tool>

</toolbox>
=============================================

web.xml 에서 VelocityViewServlet 에 init-param 으로 toolbox.xml 을 지정해 주어야 한다.

=============================================

<init-param>
  <param-name>org.apache.velocity.toolbox</param-name>
  <param-value>/WEB-INF/toolbox.xml</param-value>
</init-param>

=============================================

이렇게 적어주고... 해당 컨텍스트 리로딩..

마지막으로 test.vm 파일에 아래와 같이 적어준당..

=============================================

<BR><HR><BR>
$date.getDate()

<BR>
$date.format('yyyy-MM-dd aaa H:m:s', $date)

<BR>
$date.short || $date.medium || $date.long

<BR>
$date.get('yyyy-M-d H:m:s a')

=============================================

http://localhost:8080/velocity/test.do 

오옷... 날짜 나와따~~

이런식으로 제공되는 Tool들을 지정해서 쓰면 된당..


 

Posted by tornado
|