Multiple include tags on JSP

705 Views Asked by At

I have some question about include tags.

Is it correct to use structure like?

<c:choose>
    <c:when test="${info == 'view_users'}">
        <jsp:include page="/WEB-INF/jsp/admin/view_users.jsp" />
    </c:when>
    <c:when test="${info == 'view_products'}">
        <jsp:include page="/WEB-INF/jsp/admin/view_products.jsp" />
    </c:when>
    <c:when test="${info == 'edit_product'}">
        <jsp:include page="/WEB-INF/jsp/admin/edit_product.jsp" />
    </c:when>
    <c:when test="${info == 'view_categories'}">
        <jsp:include page="/WEB-INF/jsp/admin/view_categories.jsp" />
    </c:when>
</c:choose>

Sometimes I have an exception "JasperException: Unable to compile class for JSP". Is my problem will be solved if I use <%@ include file tag? Or do I need to give up such a structure? All included pages have fixed structure, not dynamic.

1

There are 1 best solutions below

4
Roman C On

The structure could be simplified but it won't resolve your compilation problems.

<c:import url="/WEB-INF/jsp/admin/${info}.jsp" /> 

Instead delegate this logic to controller (using MVC) to decide which view should be returned and properly initialize the view.