일반 Escape special characters

황제낙엽 2010.10.28 13:19 조회 수 : 527 추천:105

sitelink1 http://www.javapractices.com/topic/TopicAction.do?Id=96 
sitelink2  
sitelink3  
sitelink4  
sitelink5  
sitelink6  

위 character들은 사용되는 언어에 따라 특수처리 되는 경우가 있다.
가령 '<' 는 < 로 변환 처리되어야 한다.
이것은 HTML, XML, RegEx 등등 각각의 언어에 따라 다르게 설정되기도 한다

다음은 원문
 


  • <
  • >
  • "
  • '
  •  
  • &



  •  
  • Arbitrary text placed in an HTML tag often needs to be altered, to ensure that the resulting HTML remains valid.

     

    Problem characters can include

    These characters can be replaced with HTML character entities. For example, < can be replaced with <.

    Query strings (Blah=1&Name=Bob) often need to be escaped as well. If the query string contains special characters, it will need to be "URL encoded". (See the javadoc for the URLEncoder class for further information.) This will ensure the query string conforms with valid HTTP.

    There is often a second issue, however, with regard to query strings. If a query string is placed in an HREF attribute, then even a URL encoded query string is often not of valid form. This is because URLEncoder produces valid HTTP, but it does not in general produce text which is a valid HTML attribute - the ampersand character needs to be replaced by the corresponding character entity &.

    Here is an example of a utility class which escapes special characters for HTML, XML, regular expressions, and so on.

     

     

     

     

    • <
    • >
    • "
    • '
    •  
    • &

     

     

번호 제목 글쓴이 날짜 조회 수
223 String to InputSource 황제낙엽 2012.12.03 696
222 Class.getResource() vs. ClassLoader.getResource()/getResources() 황제낙엽 2012.06.24 566
221 Jar파일에 포함된 리소스 접근하는 방법(How to read a resource from a JAR file ) file 황제낙엽 2012.06.24 700
220 Java에서 URL 다루기 file 황제낙엽 2012.06.24 505
219 HttpServletResponse.setContentType(java.lang.String type) 과 MIME 타입 황제낙엽 2012.04.20 632
218 code, codebase 속성과 applet object 동적 생성 file 황제낙엽 2012.04.17 713
217 한글 파일명 깨짐으로 살펴본 다국어 처리 문제 (UTF-8) 황제낙엽 2012.03.22 10611
216 BufferedReader.readLine() hangs 황제낙엽 2012.02.23 906
215 OS 쉘 명령어(shell script) 실행하기 [ProcessBuilder, Runtime.getRuntime().exec()] 황제낙엽 2012.02.22 1135
214 PreProcess 실행 (전처리기 만들기) file 황제낙엽 2012.01.04 680
213 javax.script와 타입변환 황제낙엽 2012.01.03 740
212 Scripting within Java 황제낙엽 2012.01.03 651
211 Hex string <-> String object 황제낙엽 2011.11.29 694
210 An alternative to the deep copy technique file 황제낙엽 2011.07.27 672
209 <jsp:include>, include지시자 file 황제낙엽 2011.07.24 569
208 <jsp:include> 액션태그 황제낙엽 2011.07.24 507
207 volatile 에 대한 단상(斷想) 황제낙엽 2011.06.22 516
206 Object element 의 onerror 이벤트 황제낙엽 2011.04.21 603
205 Java 2D Graphics - Reference link 황제낙엽 2011.04.11 563
204 deployJava.js를 이용한 JRE 자동설치 및 Applet 디플로이 file 황제낙엽 2011.04.04 1193