Language/Java, Jsp

JSP - jstl 변수 공유

__bo0o_ 2022. 4. 1. 20:22

코드를 작성하다보면

JSP와 JSTL 변수를 공유해야하는 상황이 생기는데

그럴 땐 아래와 같이 사용해줍시다

<c:forEach var="item" items="${list}">

    ...

    <c:set var="temp_team_no" value="${item.team_no}" />
    <c:set var="temp_c_no" value="${item.c_no}" />
    <%
        String sql_point = "select a.* ";
        sql_point = sql_point + " ... project_no = a.c_no and c_team_no = "+ pageContext.getAttribute("temp_team_no") +" ...";
        sql_point = sql_point + " ,(select c_exp ... and c_team_no = "+ pageContext.getAttribute("temp_c_no") +"  and c_use = 0 ) as c_exp ";
        sql_point = sql_point + " from ... and a.c_project_no = "+ pageContext.getAttribute("temp_c_no") +" and a.c_use = 0 order by a.c_no asc";
        ResultSet rs_point = stmt.executeQuery(sql_point);
        int po_no = 0;
        int test_ok = 0;
    %>
    <%
    while (rs_point.next()) {
        po_no = po_no + 1;
    %>
    
    ...

JSTL c:set을 통해

JSP에서 사용할 임시 값을 넣어주고

 

pageContext.getAttribute("변수")를 사용하여

임시 값을 불러와

 

JSP에서 JSTL에서 사용하는 값을  불러와 사용하시면 됩니다.

 

https://intro0517.tistory.com/129

반응형