0

I try to include page in JSP with out.println() inside <% ... %>, but it doesn't include successfully.

I must use <% ... %> because some restrictions such as looping. Does anybody have idea about this or another way to succeed in include pages? I point out my sample case as below.

<%

 for (int i = 1; i < strVoCardList.length; i++) {

  String strUserID = strVoCardList[i][1];


  out.println("<jsp:include page='../include/include_Notification_Bar.jsp' >");

  out.println("<jsp:param name = 'strUserID' value = \""+strUserID+"'/>");

  out.println("<jsp:param name = 'strSubElementID' value = '"+i+3+"'/>");

  out.println("</jsp:include>");

 }

%>
Med
  • 628
  • 9
  • 29
  • Can you use JSTL ? If yes, then you can use tag. First, you must create scoped variable from your scripting variable. Ask us if you need help. – rickz Jan 08 '13 at 00:54

1 Answers1

1

I strongly recommend you to drop those scriptlets and JSP tags, and to use the JSTL <c:forEach> and <c:import> tags instead.

This would look like:

<c:forEach items="${strVoCardList}" var="strVoCard" varStatus="status">
    <c:import url="../include/include_Notification_Bar.jsp">
        <c:param name="strUserID" value="${strVoCard[1]}"/>
        <c:param name="strSubElementID" value="${status.count + 3}"/>
    </c:import>
</c:forEach>

See also:

Community
  • 1
  • 1
Med
  • 628
  • 9
  • 29
  • It works now by Taglib. However, I have the difficult to modify source code as Taglib now because it impacts a lot. After review the concept of include among <%@ include file ...>, and pageContext.include(...). It solved by pageContext.include("../include/include_Notification_Bar.jsp?strUserID="+strUserID+"&strSubElementID="+(i+3)); – Dean Division Jan 08 '13 at 12:38