<jsp:include>액션태그와 모듈화

Chae Yun·2021년 12월 7일
0

<jsp:param>으로 포함할 페이지에 파라미터 추가하기

[info.jsp]

<%@ page contentType="text/html; charset=utf-8 %>
<html>
<head><title>제목</tilte></head>
<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
	<td>제품번호</td><td>xxx</td>
</tr>
<tr>
	<td>가격</td><td>10,000원</td>
</tr>
</table>

<jsp:include page="infoSub.jsp" flush="flase">
	<jsp:param name="type" value="A"/>
    /*infoSub.jsp에 이름이 type이고 값이 A인 파라미터를 추가로 전달한다*/
</jsp:include>

</body>
</html>

indo.jsp는 <jsp:param> 액션 태그를 사용하여 infoSub.jsp에 type 파라미터의 값으로 A를 전달한다.


[infoSub.jsp]

<%@ page contentType="text/html; charset=utf-8 %>
<%
	String type = request.getParameter("type");
    if(type=-null){
    return;
    }
 %>
 <br>
 <table width="100%" border="1" cellpadding="0" cellspacing="0">
 <tr>
 	<td>타입</td>
    <td><b><%=type %></b></td>
 </tr>
 <tr>
 	<td>특징</td>
    <td>
    <% if(type.equals("A")){%>
    강한 내구성.
    <% }else if(type.equals("B")){%>
    뛰어난 대처 능력
    <% } %>
    	</td>
       </tr>
      </table>

infoSub.jsp는 type 파라미터의 값이 A일 때는 "강한 내구성"을 출력하므로
info.jsp를 실행하면
타입 : A
특징 : 강한내구성

0개의 댓글