본문 바로가기

NEW JAVA & JSP

JSTL 간단 정리

 

<div id="wrapper" style="margin:10px auto; width:1200px;">

<h3>jstl 표현식</h3>

<div class="conetnt-box" style="margin:10px auto; border: 1px solid #000;">

<c:set var="browser" value="${header['User-Agent']}" /><br>

brower: <c:out value="${browser}" /><p>

<c:set var="userName" value="강호동" />

<c:out value="${userName}" /><p>

<c:remove var="brower" />

brower: <c:out value="${brower}" />

</div>

 

<div class="conetnt-box" style="margin:10px auto; border: 1px solid #000;">

<c:set var="country" value="korea" />

<c:if test="${country != null}">

국가명: <c:out value="${country}" />

</c:if>

<p>

 

<c:choose>

<c:when test="${country == 'usa'}">

<c:out value="${country}"/>의 겨울은 춥다

</c:when>

<c:when test="${country == 'canada'}">

<c:out value="${country}"/>의 겨울은 더 춥다

</c:when>

<c:otherwise>

몰라

</c:otherwise>

</c:choose>

</div>

 

<div class="conetnt-box" style="margin:10px auto; border: 1px solid #000;">

<c:forEach var="i" begin="1" end="10">

<c:out value="${i % 2 == 0}"/>

</c:forEach>

<p>

<c:forEach var="head" items="${headerValues}">

param: <c:out value="${head.key}"/><br>

value:

<c:forEach var="val" items="${head.value}">

<c:out value="${val}"/>

</c:forEach>

</c:forEach>

</div>

 

<div class="conetnt-box" style="margin:10px auto; border: 1px solid #000;">

<c:forTokens var="tech" items="강호동,한효주,이승엽,양준혁" delims=",">

<c:out value="${tech}"/><br>

</c:forTokens>

</div>

 

<div class="conetnt-box" style="margin:10px auto; border: 1px solid #000;">

<c:import url="/WEB-INF/views/common/footer.jsp" var="url"/>

<%-- ${url} --%>

</div>

 

<div class="conetnt-box" style="margin:10px auto; border: 1px solid #000;">

<%-- <c:redirect url="http://naver.com"/>--%>

</div>

 

<div class="conetnt-box" style="margin:10px auto; border: 1px solid #000;">

<fmt:requestEncoding value="utf-8"/>

파라미터: <c:out value="${param.name}"/>

<form action="/jstl" method="post">

이름: <input type="text" name="name"/><br>

<button type="submit">send</button>

</form>

</div>

 

<div class="conetnt-box" style="margin:10px auto; border: 1px solid #000;">

number: <fmt:formatNumber value="12345.6789" type="number"/>

number: <fmt:formatNumber value="12345.6789" type="currency" currencySymbol="\\"/>

number: <fmt:formatNumber value="12345.6789" type="percent"/>

number: <fmt:formatNumber value="12345.6789" pattern=".000"/>

</div>

 

<div class="conetnt-box" style="margin:10px auto; border: 1px solid #000;">

<%

Date nowTime = new Date();

SimpleDateFormat sf = new SimpleDateFormat("yyyy년 MM월 dd일 a hh:mm:ss");

System.out.println("date:" + nowTime);

%>

타입: <%=nowTime%><br>

<c:set var="nowTime" value="<%=new Date()%>"/>

시간: <c:out value="${nowTime}"/><br>

fmt시간: <fmt:formatDate value="${nowTime}" pattern="yy/MM/dd hh:mm:ss"/>

</div>

 

 

</div>

 

 

// mySql 에서 날짜를 String으로 불러오면 에러가 난다.  아래는 에러 해결 코드

<fmt:parseDate var="parseDate" value="${list.regTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
<fmt:formatDate value="${parseDate}" pattern="yy/MM/dd"/>

 

 

 

// String을 int로..

<span class="backgroundColorYellow02">
1:<fmt:parseNumber var="parseInt" value="${list.progress}"/><br>
2:<fmt:formatNumber var="progressN" value="${parseInt}"/><br>
3:<c:set var="progress" value="${progressN}"/><br>
4:<c:out value="${progress}"/><br>
<c:choose>
<c:when test="${progress == 2}">
신청완료<c:out value="${progress}"/>
</c:when>
<c:when test="${progress >= 2}">
접수완료<c:out value="${progress}"/>
</c:when>
<c:otherwise>
몰라
</c:otherwise>
</c:choose>
</span>

 

 

<span class="backgroundColorYellow02">
<fmt:parseNumber var="parseInt" value="${list.progress}"/>
<c:choose>
<c:when test="${parseInt == 2}">
접수완료
</c:when>
<c:when test="${parseInt >= 2}">
접수완료
</c:when>
<c:otherwise>
접수완료
</c:otherwise>
</c:choose>
</span>

 

 

// 이름 * 표시

<c:choose>
<c:when test="${empty list.estimateName}">
홍길동
</c:when>
<c:otherwise>
 ${fn:substring(list.estimateName,0,1) }
 <c:forEach begin="2" end="${fn:length(list.estimateName)}" step="1">
 *
 </c:forEach>
</c:otherwise>
</c:choose>

 

 

<c:if test="${!empty list.estimateName}">
${fn:substring(list.estimateName,0,1) }
<c:forEach begin="2" end="${fn:length(list.estimateName)}" step="1">
*
</c:forEach>
</c:if>