ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 211111_jstl_porm,if,when,choose
    카테고리 없음 2021. 11. 11. 11:29

    <%@ page language="java" contentType="text/html; charset=UTF-8"

        pageEncoding="UTF-8"%>

            

    <!-- 태그 -->

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

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

          

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="UTF-8">

    <link href="https://fonts.googleapis.com/css2?family=Do+Hyeon&display=swap" rel="stylesheet">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

    <script src="https://code.jquery.com/jquery-3.5.0.js"></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

    <title>Insert title here</title>

    </head>

    <body>

    <!-- post방식은 한글깨짐 -->

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

     

    <!-- value="${param.age}"가 request.getparameter("age")와 같은 의미 -->

     

    <form action="ex3_jstl.jsp" method="post">

      <table class="table table-bordered" style="width: 300px;">

        <tr>

          <th bgcolor="orange" width="100">이름</th>

            <td>

              <input type="text" name="name" class="form-control" style="width: 120px;" value="${param.name}">

            </td>

        </tr>

        

        <tr>

          <th bgcolor="orange" width="100">나이</th>

            <td>

              <input type="text" name="age" class="form-control" style="width: 120px;" value="${param.age}">

            </td>

        </tr>

        

        <tr>

          <th bgcolor="orange" width="100">급여</th>

            <td>

              <input type="text" name="pay" class="form-control" style="width: 120px;" value="${param.pay}">

            </td>

        </tr>

        

        <tr>

          <th bgcolor="orange" width="100">가고 싶은<br>나라(이유)</th>

            <td>

              <input type="text" name="nara" class="form-control" style="width: 120px;" value="${param.nara}">

            </td>

        </tr>

        

        <tr>

          <td colspan="2" align="center" bgcolor="orange">

            <button type="submit" class="btn btn-success">결과확인</button>

          </td>

        </tr>

      </table>

    </form>

     

     

    <hr>

    <!-- 이름을 입력했을 경우에만 div 출력 -->

    <c:if test="${!empty param.name}">

      <div class="alert alert-info" style="width: 400px; font-size: 1.2em;">

        이름: ${param.name}<br>

        

        나이: ${param.age}세(

        <c:if test="${param.age>=20}">

          <span style="color: magenta;">성인</span>

        </c:if>

        <!-- jstl에는 if문에 else가 없음.. 조건 주고 싶으면 또 조건을 줘야 함 -->

        <c:if test="${param.age<20}">

          <span style="color: red;">미성년</span>

        </c:if>

        )<br>

        

        급여: <fmt:formatNumber value="${param.pay}" type="currency"/><br>

        

        가고싶은 나라(이유): ${param.nara}<br>

         <b style="padding-left: 30px;">

           <c:choose>

             <c:when test="${param.nara=='프랑스'}">

               프랑스(에펠탑,쇼핑)

             </c:when>

             

             <c:when test="${param.nara=='호주'}">

               호주(서핑)

             </c:when>

             

             <c:when test="${param.nara=='하와이'}">

               하와이(수영)

             </c:when>

             

             <c:when test="${param.nara=='크로아티아'}">

               크로아티아(동유럽이 좋음)

             </c:when>

             

             <c:otherwise>

               ${param.nara}은/는 별로 관심이 없다

             </c:otherwise>

           </c:choose>

         </b>

      </div>

    </c:if>

     

    </body>

    </html>

     

    댓글

Designed by Tistory.