예: tsx:repeat JavaServer Pages 태그를 사용하여 결과 세트 반복(사용되지 않음)
<tsx:repeat> 태그는 결과 세트를 반복합니다. 결과 세트는 Bean 내에 포함되어 있습니다. Bean은 정적 Bean(예: IBM® WebSphere® Studio 데이터베이스 마법사를 사용하여 작성되는 Bean)이거나 동적으로 생성되는 Bean(예: <tsx:dbquery> 구문을 사용하여 생성되는 Bean)일 수 있습니다.
제거된 기능: JSP(JavaServer Pages) 엔진에서 tsx 태그에 대한 지원은
WebSphere Application Server 버전 6.0에서 더 이상 사용되지 않습니다.
tsx 태그를 사용하는 대신, JSTL(JavaServer Pages Standard Tag Library)에서 동일한 태그를 사용해야 합니다. depfeat다음 표는 myBean이라는 Bean의 컨텐츠를 그래픽으로 표시합니다.
| 열 | col1 | col2 | col3 |
|---|---|---|---|
| row0 | friends | Romans | countrymen |
| row1 | bacon | lettuce | tomato |
| row2 | May | June | July |
다음은 Bean에 대한 정보입니다.
- 데이터베이스 테이블에 있는 열 이름이 Bean의 특성 이름이 됩니다. <tsx:dbquery> 섹션은 열 이름을 다른 특성 이름에 맵핑하는 기술을 설명합니다.
- Bean 특성이 색인화됩니다. 예를 들어, myBean.get(Col1(row2))는 May를 리턴합니다.
- 조회 결과는 행에 있습니다. <tsx:repeat> 태그는 시작 행에서 시작하여 행을 반복합니다.
다음 표는 <tsx:repeat> 태그를 사용한 정적 Bean 반복을 동적으로 생성되는 Bean에 대해 비교합니다.
| 정적 Bean 예 | <tsx:repeat> Bean 예 |
|---|---|
myBean.class // Code to get a connection // Code to get the data Select * from myTable; // Code to close the connectionJSP 파일 <tsx:repeat index=abc>
<tsx:getProperty name="myBean"
property="col1(abc)" />
</tsx:repeat>
참고:
|
JSP 파일<tsx:dbconnect id="conn"
userid="alice"passwd="test"
url="jdbc:db2:sample"
driver="COM.ibm.db2.jdbc.app.DB2Driver">
</tsx:dbconnect >
<tsx:dbquery id="dynamic"
connection="conn" >
Select * from myTable;
</tsx:dbquery>
<tsx:repeat index=abc>
<tsx:getProperty name="dynamic"
property="col1(abc)" />
</tsx:repeat>
참고:
|
내재적(implicit) 및 명시적(explicit) 색인 작성
예 1, 2, 3에서는 <tsx:repeat> 태그의 사용법을 보여줍니다. 모든 색인화된 특성이 300개 이하의 요소를 가지면 예에서 동일한 출력을 생성합니다. 300개보다 많은 요소가 있는 경우, 예 1, 2에서는 모든 요소를 표시하는 반면 예 3에서는 처음 300개의 요소만을 표시합니다.
예 1에서는 기본 시작 색인 및 종료 색인이 있는 내재적 색인을 보여줍니다. 색인화된 특성 수가 가장 적은 Bean은 루프 반복 수를 제한합니다.
<table> <tsx:repeat> <tr><td><tsx:getProperty name="serviceLocationsQuery" property="city" /> </tr></td> <tr><td><tsx:getProperty name="serviceLocationsQuery" property="address" /> </tr></td> <tr><td><tsx:getProperty name="serviceLocationsQuery" property="telephone" /> </tr></td> </tsx:repeat> </table>
예 2에서는 색인화, 시작 색인 및 종료 색인을 보여줍니다.
<table> <tsx:repeat index=myIndex start=0 end=2147483647> <tr><td><tsx:getProperty name="serviceLocationsQuery" property=city(myIndex) /> </tr></td> <tr><td><tsx:getProperty name="serviceLocationsQuery" property=address(myIndex) /> </tr></td> <tr><td><tsx:getProperty name="serviceLocationsQuery" property=telephone(myIndex) /> </tr></td> </tsx:repeat> </table>
예 3에서는 명시적 색인화 및 내재적 시작 색인을 가진 종료 색인을 보여줍니다. 색인 속성이 지정되더라도 (myIndex) 태그가 필수가 아니므로 색인화된 특성 city를 여전히 내재적으로 색인화될 수 있습니다.
<table> <tsx:repeat index=myIndex end=299> <tr><td><tsx:getProperty name="serviceLocationsQuery" property="city" /t> </tr></td> <tr><td><tsx:getProperty name="serviceLocationsQuery" property="address(myIndex)" /> </tr></td> <tr><td><tsx:getProperty name="serviceLocationsQuery" property="telephone(myIndex)" /> </tr></td> </tsx:repeat> </table>
<tsx:repeat> 블록 중첩
<tsx:repeat> 블록을 중첩시킬 수 있습니다. 각 블록은 별도로 색인화됩니다. 이 기능은 두 개의 Bean의 인터리빙 특성 또는 부속 특성을 가진 특성에 유용합니다. 예에서는 두 <tsx:repeat> 블록이 중첩되어 사용자 장바구니에 있는 각 컴팩트 디스크의 노래 목록을 표시합니다.
<tsx:repeat index=cdindex>
<h1><tsx:getProperty name="shoppingCart" property=cds.title /></h1>
<table>
<tsx:repeat>
<tr><td><tsx:getProperty name="shoppingCart" property=cds(cdindex).playlist />
</td></tr>
</tsx:repeat>
</table>
</tsx:repeat>
참조 주제