HTML 태그 안에서 특수문자 사용하기



HTML안에서 특수문자를 사용할 경우 HTML태그가 깨지는 경우가 발생 할 수도 있으므로 특수문자의 경우 치환해서 사용한다.


HTML안에서 자주 사용되는 특수문자는 아래와 같다.




 심볼

 HTML

" 

 #

# 

$

$ 

 %

%

 &

 &

 '

' 

 (

( 

 )

) 

 /

 /

 :

: 

 ;

 ;

 <

&lt; 

 >

 &gt;

 &equals;

 \

 &bsol;


예제

달라나 원화같이 통화를 HTML로 표현할 경우 위의 HTML을 찾아서 맡는 문자로 대체 하면 된다.



<html>
   <head>
      <title>특수문자 표시하기</title>
   </head>
   <body>
      <h3>한화로 표현하기</h3>
      <p>&bsol; 1,000</p>
      <h3>US 달러로 표현하기</h3>
      <p>&dollar; 1,000</p>
   </body>
</html>




<c:choose>


<c:choose>는 자바의 Switch문과 비슷한 역할을 합니다.


<c:when>

case와 같은 역할을 하는것은 <c:choose>안의 <c:when>태그 입니다.


<c:otherwise>

default문 같은 역할을 사용하고 싶으면 <c:shoose>태그 안에 <c:otherwise>태그를 사용합니다.


속성


<c:choose><c:otherwise> 는 속성을 사용하지 않습니다.


<c:when>은 test 속성을 사용합니다.(필수)


예제


숫자를 비교하여 HTML의 문장을 변경하는 예제이다.


<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>

<html>
   <head>
      <title>예제 example</title>
   </head>

   <body>
      <c:set var = "money" scope = "session" value = "${5000}"/>
      <p>내가 가진 돈은  : <c:out value = "${salary}"/>원 이다.</p>
      <c:choose>
         <c:when test = "${money<= 0}">
            돈 한푼도 없어요.
         </c:when>
         <c:when test = "${money > 5000}">
            담배 한갑정도 살 수 있어요.
         </c:when>
         <c:otherwise>
            답이 없네...
         </c:otherwise>
      </c:choose>
   </body>
</html>



'JAVA' 카테고리의 다른 글

[JAVA] 패스워드 정규식 (Regex)  (1) 2017.12.05
[JSP] jstl 과 el의 차이점  (0) 2017.12.04
[JSTL]fmt:formatNumber  (0) 2017.11.22
VO, Map 객체 JSON 으로 변환  (0) 2017.11.19
java의 map이나 VO 객체를 JSON으로  (1) 2017.11.17

<fmt:formatNumber>사용법


formatNumber는 숫자, 퍼센트, 돈단위를 작성할 때 사용한다.


formatNumber을 이용하여 숫자 단위마다 콤마 자동 찍기


formatNumber의 속성 중 type에 값을 number로 하면 3자리마다 콤마가 설정된다.
type의 속성 값에 할당 할 수 있는 값은 number, percentage, currency가 있다.

예제



<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>

<html>
   <head>
      <title>formatNumber</title>
   </head>
   <body>
      <h3>단위마다 콤마 찍기</h3>
      <c:set var = "money" value = "25000" />
      <p>\<fmt:formatNumber value = "${money}" type = "number"/></p>
   </body>
</html>


formatNumber을 이용하여 통화 단위로 표현하기


type속성에 currency를 사용하면 돈 단위와 액수를 표현할 수 있다.


예제



<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>

<html>
   <head>
      <title>formatNumber</title>
   </head>
   <body>
      <h3>한화로 표현하기</h3>
      <c:set var = "money" value = "25000" />
      <p><fmt:formatNumber value = "${money}" type = "currency" currencySymbol = "\"/></p>
      <h3>US 달러로 표현하기</h3>
      <fmt:setLocale value = "en_US"/>
      <p><fmt:formatNumber value = "${money}" type = "currency"/></p>
   </body>
</html>


위의 결과 값을 보면 

첫번째 한화로 표현현 값은

\25,000.00

두번째 US달러로 표현한 값은 

$25,000.00

으로 표현된다.

currency 는 소수점 두째자리까지 표현된다.


'JAVA' 카테고리의 다른 글

[JAVA] 패스워드 정규식 (Regex)  (1) 2017.12.05
[JSP] jstl 과 el의 차이점  (0) 2017.12.04
[JSTL]choose와 when, otherwise 사용법  (0) 2017.11.23
VO, Map 객체 JSON 으로 변환  (0) 2017.11.19
java의 map이나 VO 객체를 JSON으로  (1) 2017.11.17

+ Recent posts