I have the following jsp
...
<table id="table" class="sortable">
<thead>
<tr>
<td class="head">Дата Запроса</td>
<td class="head">Сумма Запроса</td>
<td class="head">Баланс Владельца</td>
<td class="head">Статус Запроса</td>
<td class="head">Email</td>
<td class="head">-----</td>
</tr>
</thead>
<tbody>
<c:forEach var="event" items="${events}">
<tr>
<td>
<jsp:useBean id="dateValue" class="java.util.Date"/>
<jsp:setProperty name="dateValue" property="time"
value="${event.timestamp}"/>
<fmt:formatDate value="${dateValue}"
pattern="MM/dd/yyyy HH:mm"/>
</td>
<td>${event.amount}</td>
<td>${event.sourceUser.userAccounts.iterator().next().currentAmount}</td>
<td>${event.status}</td>
<td>${event.sourceUser.email}</td>
<td><c:if test="${event.status != 'SUCCESS'}">
<input type="button" class="withDraw"
value="подтвердить вывод"/>
</c:if>
<div class="edit-holder adt" id="">
<div class="edit-box">
<div class="title">Подтверждение вывода средств владельцем</div>
<form action="/admin/confirmWithdrawRequest"
method="post">
<div>
<input type="hidden" value="${event.id}" name="eventId"/>
<label>Статус</label>
<select name="status">
<c:forEach items="${statuses}" var="status">
<option <c:if test="${status == event.status}">
selected="selected"
</c:if>
>${status}</option>
</c:forEach>
</select>
<div class="clear"/>
</div>
<div>
<label>Email</label>
<input type="text" class="with-draw-input" name="email"
value="${event.sourceUser.email}"
readonly/>
<div class="clear"/>
</div>
<div>
<label>Текущий баланс</label>
<input type="text" class="with-draw-input" name="balance"
value="${event.sourceUser.userAccounts.iterator().next().currentAmount}"
readonly/>
<div class="clear"/>
</div>
<div>
<label>Сумма запроса</label>
<input type="text" class="with-draw-input" name="email"
value="${event.amount}"
readonly/>
<div class="clear"/>
</div>
<div>
<label>Комментарий модератора</label>
<textarea class="moderationComment"
name="moderationComment">${event.moderationComment}</textarea>
<div class="clear"/>
</div>
<input type="submit" class="btn" value="сохранить"/>
<div class="clear"></div>
</form>
<div class="close"></div>
</div>
</div>
</td>
</tr>
</c:forEach>
</tbody>
</table>
...
Now it is compiles good and I see expected result:
I want to extract last td
content to separated jsp like this:
<tbody>
<c:forEach var="event" items="${events}">
<tr>
<td>
<jsp:useBean id="dateValue" class="java.util.Date"/>
<jsp:setProperty name="dateValue" property="time"
value="${event.timestamp}"/>
<fmt:formatDate value="${dateValue}"
pattern="dd.MM.yyyy HH:mm:ss"/>
</td>
<td>${event.amount}</td>
<td>${event.sourceUser.userAccounts.iterator().next().currentAmount}</td>
<td>${event.status}</td>
<td>${event.sourceUser.email}</td>
<td><jsp:include page="confirmWithDrawModal.jsp"/>
</td>
</tr>
</c:forEach>
</tbody>
and confirmWithDrawModal.jsp
:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<c:if test="${event.status != 'SUCCESS'}">
<input type="button" class="withDraw"
value="подтвердить вывод"/>
</c:if>
<div class="edit-holder adt" id="">
<div class="edit-box">
<div class="title">Подтверждение вывода средств владельцем</div>
<form action="/admin/confirmWithdrawRequest"
method="post">
<div>
<input type="hidden" value="${event.id}" name="eventId"/>
<label>Статус</label>
<select name="status">
<c:forEach items="${statuses}" var="status">
<option <c:if test="${status == event.status}">
selected="selected"
</c:if>
>${status}</option>
</c:forEach>
</select>
<div class="clear"/>
</div>
<div>
<label>Email</label>
<input type="text" class="with-draw-input" name="email"
value="${event.sourceUser.email}"
readonly/>
<div class="clear"/>
</div>
<div>
<label>Текущий баланс</label>
<input type="text" class="with-draw-input" name="balance"
value="${event.sourceUser.userAccounts.iterator().next().currentAmount}"
readonly/>
<div class="clear"/>
</div>
<div>
<label>Сумма запроса</label>
<input type="text" class="with-draw-input" name="email"
value="${event.amount}"
readonly/>
<div class="clear"/>
</div>
<div>
<label>Комментарий модератора</label>
<textarea class="moderationComment"
name="moderationComment">${event.moderationComment}</textarea>
<div class="clear"/>
</div>
<input type="submit" class="btn" value="сохранить"/>
<div class="clear"></div>
</form>
<div class="close"></div>
</div>
</div>
and after this refactoring I see following result:
As you can see variables is not rendered.
How to fix it?
A .jsp
file gets translated to a .java
file, which is compiled and run, providing output that ultimately gets sent to the browser.
When you include another jsp within a jsp how those get translated and compiled depends on which form of include you use.
<jsp:include page="incpage.jsp">
translates and compiles mainpage.jsp and incpage.jsp separately and inserts the output of incpage.jsp at the include location. Thinking of this situation, incpage.jsp is independent of mainpage.jsp so (naturally) doesn't have access to those variables.
<%@include file="incpage.jsp">
is more like a C #include
where the contents of incpage.jsp are copied into mainpage.jsp before translation and compilation take place. In this case it doesn't even matter if inpage has a .jsp extension.
If you want the included file to act as part of the main file, as it seems you do, you would use the second form of include — <%@include ...>