JSP
JSP -> JSTL 변경
햄볶는뚱땡이
2009. 11. 17. 14:03
JSP 페이지 에서 스크립트릿 <% %> 을 사용하는 대신에 JSTL 태그를 쓰겠다는 ANTOP의 강력한 주장에 의해 어쩔수 없이 변경하는 도중.....
까먹을까봐서리 냉겨 둬야지...
이랬던 스크립트릿을 JSTL 로 변경하게 되면! 단 3줄로 끝 낼 수가 있겠습니다.
최종 exam >>>>>
은근히 하다 보니깐 간편한 코딩이 되는걸 보고는 깜놀~ 오 놀라워라~ ㅎㅎ
까먹을까봐서리 냉겨 둬야지...
<%
클래스명 객체1 = (클래스명)request.getAttribute("받은VO");
List 객체2 = (ArrayList)객체1.get메소드();
List 객체2 = (ArrayList)객체1.get메소드();
%>
<%
if ( 객체2.size() != null || 객체2.size() != 0 ){
<%
if ( 객체2.size() != null || 객체2.size() != 0 ){
for ( int i = 0; i < 객체2.size() ; i++ ){
객체1 = (클래스명)객체2.get(i) ;
%>
객체1 = (클래스명)객체2.get(i) ;
%>
<%=객체1.get메소드1()%>
<%=객체1.get메소드2()%>
<%=객체1.get메소드3()%>
<%=객체1.get메소드2()%>
<%=객체1.get메소드3()%>
<%
}
}
%>
이랬던 스크립트릿을 JSTL 로 변경하게 되면! 단 3줄로 끝 낼 수가 있겠습니다.
<c:forEach items="${받은VO.소문자메소드}" var = " 변수명" >
<c:out value =" ${ 변수명 . 소문자메소드 }" >
</c:forEach>
<c:out value =" ${ 변수명 . 소문자메소드 }" >
</c:forEach>
최종 exam >>>>>
######### 스크립트릿 이용 #########
<%
Hello_InVo inVo = (Hello_InVo)request.getAttribute("helloVo");
List usertable = (ArrayList)inVo.getUsertable();
%>
<%
if(usertable.size() != 0 || usertable != null) {
for( int i=0; i < usertable.size(); i++){
inVo = (Hello_InVo)usertable.get(i);
%>
<tr>
<td> <%=inVo.getUserPk() %></td>
<td> <%=inVo.getUserId() %></td>
<td> <%=inVo.getUserName() %></td>
</tr>
<%
}
}
%>
######### JSTL 이용 #########
<c:forEach items="${helloVo.usertable}" begin="0" step="1" var="outVo">
<td><c:out value="${outVo.userPk}" /></td>
<td><c:out value="${outVo.userId}" /></td>
<td><c:out value="${outVo.userName }"/> </td>
</c:forEach>
items에 속한(즉 helloVo) 것을 request에서 가져와서
한개씩 outVo라는 이름으로 세팅합니다..
그 담에 outVo에서 userPk(reflection에 의해 getUserPk을 호출하게 되어 있습니다) 속성을 가져와 뿌려줌
<%
Hello_InVo inVo = (Hello_InVo)request.getAttribute("helloVo");
List usertable = (ArrayList)inVo.getUsertable();
%>
<%
if(usertable.size() != 0 || usertable != null) {
for( int i=0; i < usertable.size(); i++){
inVo = (Hello_InVo)usertable.get(i);
%>
<tr>
<td> <%=inVo.getUserPk() %></td>
<td> <%=inVo.getUserId() %></td>
<td> <%=inVo.getUserName() %></td>
</tr>
<%
}
}
%>
######### JSTL 이용 #########
<c:forEach items="${helloVo.usertable}" begin="0" step="1" var="outVo">
<td><c:out value="${outVo.userPk}" /></td>
<td><c:out value="${outVo.userId}" /></td>
<td><c:out value="${outVo.userName }"/> </td>
</c:forEach>
items에 속한(즉 helloVo) 것을 request에서 가져와서
한개씩 outVo라는 이름으로 세팅합니다..
그 담에 outVo에서 userPk(reflection에 의해 getUserPk을 호출하게 되어 있습니다) 속성을 가져와 뿌려줌
은근히 하다 보니깐 간편한 코딩이 되는걸 보고는 깜놀~ 오 놀라워라~ ㅎㅎ