달력

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
오늘 회사메일에 지방에 파견나가신 김모과장님이 보내신 글을 읽어보니...
유익한 정보일 거 같아서 끄적여 본다.
 
============================= 발췌 부분 시작 ======================================
JSP 2.0의 el( ${} )과 jstl(c, fmt, fn)을 쓰다보면 이렇게 편할수 있구나 하고 느꼇는데...
뭔가 부족한게 있어서 fn관련 Soruce를 보게 되었는데..
헉....  fn.tld를 보면 <function>이라는 tag에 class명과 호출 방식으로 선언되어 있고
Classs를 보면 일반 Static function을 바로 불러 쓰고 있었습니다.
다음은 fn.tld의 예 인데.. 너무 단순하지요...
taglib를 만든 다기 보다는 taglib에 기존 Class 함수를 정의만 해두면 되니까요.
 
예제
------------------- [mi-html-util.tld]----------------
 <function>
  <description>
   New line to br tag
  </description>
  <name>nl2br</name>
  <function-class>
   javacross.util.HTMLUtil
  </function-class>
  <function-signature>
   java.lang.String nl2br(java.lang.String)
  </function-signature>
  <example>
   ${mhtml:nl2br(String txt)}
  </example>
 </function>
 ---------------- HTMLUtil.java --------------
package javacross.util;
public class HTMLUtil {
    static final RE reg_NL = new RE("(\015\012)|(\015)|(\012)");
 
    public static String nl2br(String txt){
       if (txt == null) {
           return null;
       } else {
          return reg_NL.subst(txt,"<br />" );
      }
  }
 
public static String null2nbsp(String txt){
  if (txt == null) {
   return "&nbsp;";
  } else {
   return txt;
  }
 }
}
------------------- test.jsp ----------------------
<%@ page language="java" contentType="text/html; charset=MS949" %>
<%@ taglib prefix="mhtml" uri="/WEB-INF/tld/mi-html-util.tld" %>
<table>
 <tr>
  <th>테스트 해보기</th>
 </tr>
 <tr>
  <td>${mhtml:nl2br(course.first_remark)}</td>
 </tr> 
</table>
============================= 발췌 부분 끝 ========================================
 
김과장님... 항상 유익한 정보 감사드립니다. ^^
Posted by tornado
|