일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 허드슨 포트 변경
- 시퀀스 초기화 프로시져
- 전화번호 형식 자동 변환
- jquery_api #jquery #api
- css 말줄임
- Spring Annotation
- 화면보호기 실행 방지
- 폴더만 남기고 파일만 삭제
- eclipse 다국어
- DIV 팝업 이외 영역 클릭 시 팝업 닫기
- eclipse 폰트
- javascript Camel
- #오라클 데이터 복구
- 탭과 클릭 focus 이벤트 구분
- ajax 배열
- jquery_cheat_sheet #jquery_quick_api_reference
- 엑셀 UPDATE
- javascript 낙타
- 트리거 이벤트
- 스킵 네비게이션
- 뒤로가기 방지
- 근무날짜 경력계산
- eclipse properties
- JSP Standard Tag Library (JSTL) Tutorial
- i_tail
- ajax 배열 파라미터
- taglib 만들기
- jQuery 백스페이스
- 여러줄 한줄로
- 팝업 종료
Archives
- Today
- Total
Hi~ Summers!!
taglib 만들기 본문
1. WEB-INF/tld/밑에 파일을 만든다.
예) f.tld
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 32 33 34 35 36 37 38 39 40 41 42 43 | <?xml version="1.0" encoding="UTF-8" ?> <taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0"> <description>JSTL 1.1 functions library</description> <display-name>JSTL XML</display-name> <tlib-version>1.1</tlib-version> <short-name>s</short-name> <function> <description>String Replace</description> <name>htmlCharToSpecialChar</name> <function-class>my.test.util.StringUtil</function-class> <function-signature>java.lang.String htmlCharToSpecialChar(java.lang.String , boolean)</function-signature> <example> ${s:htmlCharToSpecialChar(str, true)} </example> </function> <function> <description>String Replace</description> <name>specialCharToHtmlChar</name> <function-class>my.test.util.StringUtil</function-class> <function-signature>java.lang.String specialCharToHtmlChar(java.lang.String , boolean)</function-signature> <example> ${s:specialCharToHtmlChar(str, true)} </example> </function> <function> <description>String Replace</description> <name>htmlCharToEmpty</name> <function-class>my.test.util.StringUtil</function-class> <function-signature>java.lang.String htmlCharToEmpty(java.lang.String)</function-signature> <example> ${s:htmlCharToEmpty(str)} </example> </function> </taglib> |
2. my.test.util 패키지 안에 StringUtil 클래스를 만든다.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | package my.test.util; public class StringUtil { /** *<pre> * 인자로 받은 String을 특수문자로 변환한다. * @param 문자열, boolean값 (textarea 인지 그냥 text 인지) * @return 변환된 str *</pre> */ public static String htmlCharToSpecialChar(String str, boolean txtArea){ str = str.replaceAll("<", "<"); str = str.replaceAll(">", ">"); str = str.replaceAll(" ", " "); if(txtArea == true) str = str.replaceAll("\r\n", "<br/>"); else str = str.replaceAll("\n", "<br/>"); str = str.replaceAll("'", "'"); str = str.replaceAll("\"", """); return str; } /** *<pre> * 인자로 받은 String의 특수문자를 일반문자로 변환한다. * @param 문자열, boolean값 (textarea 인지 그냥 text 인지) * @return 변환된 str *</pre> */ public static String specialCharToHtmlChar(String str, boolean txtArea){ str = str.replaceAll("<", "<"); str = str.replaceAll(">", ">"); str = str.replaceAll(" ", " "); if(txtArea == true){ str = str.replaceAll("<br/>", "\r\n"); str = str.replaceAll("<br>", "\r\n"); }else{ str = str.replaceAll("<br/>", "\n"); str = str.replaceAll("<br>", "\n"); } str = str.replaceAll("'", "'"); str = str.replaceAll(""", "\""); return str; } /** *<pre> * 인자로 받은 String의 html문자를 공백으로 치환한다. * @param 문자열 * @return 변환된 str *</pre> */ public static String htmlCharToEmpty(String str){ str = str.replaceAll("<", ""); str = str.replaceAll(">", ""); str = str.replaceAll(" ", ""); str = str.replaceAll("'", ""); str = str.replaceAll("\"", ""); return str; } } |
3. jsp에서 사용한다.
1 2 3 | <%@ taglib prefix="f" uri="/WEB-INF/tld/f.tld" %> ${f:specialCharToHtmlChar(content, true)} |
[출처] 나만의 taglib 만들기|작성자 joypheonix
Comments