본문 바로가기

WEB_Programming/JSTL

17. JSTL Form Action

1. 동일한 페이지로 전송하기
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
  <head>
    <title>If with Body</title>
  </head>

  <body>
    <c:if test="${pageContext.request.method=='POST'}">
      <c:if test="${param.guess=='5'}">You guessed my number!
      <br />

      <br />

      <br />
      </c:if>

      <c:if test="${param.guess!='5'}">You did not guess my number!
      <br />

      <br />

      <br />
      </c:if>
    </c:if>

    <form method="post">Guess what number I am thinking of?
    <input type="text" name="guess" />

    <input type="submit" value="Try!" />

    <br />
    </form>
  </body>
</html>

2. 파라미터를 통한 자기 참조 방법
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<c:set var="totalCount" scope="session" value="100"/>
<c:set var="perPage" scope="session" value="20"/>

<c:forEach
    var="boundaryStart"
    begin="0"
    end="${totalCount - 1}"
    step="${perPage}">

    <a href="?start=<c:out value="${boundaryStart}"/>">
      [
        <c:out value="${boundaryStart}"/>
         -
        <c:out value="${boundaryStart + perPage - 1}"/>
      ]
    </a>
</c:forEach>

<c:forEach
    var="current"
    varStatus="status"
    begin="${param.start}"
    end="${param.start + perPage - 1}">
  <c:if test="${status.first}">
    <ul>
  </c:if>
  <li><c:out value="${current}"/></li>
  <c:if test="${status.last}">
    </ul>
  </c:if>
</c:forEach>


3. JSTL의 폼 파라미터
3.1 form.jsp
<html>
  <head>
  </head>

  <body>
    <form method="POST" action="form2.jsp">
      <table border="1" cellpadding="0" cellspacing="0"
      style="border-collapse: collapse" bordercolor="#111111"
      width="42%" id="AutoNumber1">
        <tr>
          <td width="100%" colspan="2" bgcolor="#0000FF">
            <p align="center">
              <b>
                <font size="4" color="#FFFFFF">Please Login</font>
              </b>
            </p>
          </td>
        </tr>

        <tr>
          <td width="19%">User Name</td>

          <td width="81%">
            <input type="text" name="uid" size="20" />
          </td>
        </tr>

        <tr>
          <td width="19%">Password</td>

          <td width="81%">
            <input type="password" name="pwd" size="20" />
          </td>
        </tr>

        <tr>
          <td width="100%" colspan="2">
            <p align="center">
              <input type="submit" value="Submit" name="action" />

              <input type="reset" value="Reset" name="B2" />
            </p>
          </td>
        </tr>
      </table>
    </form>

    <p align="left">
      <i>Note: you may use any ID/Password, security is not
      checked.</i>
    </p>
  </body>
</html>


3.2 form2.jsp
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
  <h3>Welcome back
  <c:out value="${param.uid}" />

  !</h3>
</html>

4. JSTL에서 폼 파라미터와 요청 파라미터의 이용
4.1 form.jsp
<html>
  <head>
    <title>Set page parameters (2)</title>
  </head>
  <body>
    This page allows you to enter information that is sent as request
    parameters to another page.<br />

    The next page list the different parameters with their values. <P />

    <form action="listPageParameters.jsp" method="get">
      <table>
        <tr><td>Enter an adjective:</td>
            <td><input type="text" name="adjective" /></td>
        </tr>
        <tr><td>Enter an adjective:</td>
            <td><input type="text" name="adjective" /></td>
        </tr>
        <tr><td>Enter a noun:</td>
            <td><input type="text" name="noun" /></td>
        </tr>
        <tr><td>Enter a noun:</td>
            <td><input type="text" name="noun" /></td>
        </tr>
      </table>
      <input type="submit" value="Send parameters" />
    </form>
  </body>
</html>

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

<html>
  <head>
    <title>List page parameters</title>
  </head>
  <body>
    You entered the following parameters:<br />
    <ul>
      <c:forEach var="pageParameter" items="${param}">
        <li> <c:out value="pageParameter" /> has the values
        <c:forEach var="currentValue" items="${pageParameter.value}">
          <c:out value="${currentValue}" />
        </c:forEach>
      </c:forEach>
    </ul>
  </body>
</html>

'WEB_Programming > JSTL' 카테고리의 다른 글

JSTL IBM 강좌  (0) 2008.10.15
[JSTL] jstl 함수  (0) 2008.07.27
16. JSTL Form TextField  (0) 2008.06.24
15. JSTL 폼 Select 예제  (0) 2008.06.24
14. JSTL Input 폼 처리  (0) 2008.06.20