Good day, I’m a beginner learning Jave EE. I created a servlet (controller) VersionOverview.java that contains following code in the doGet method:
RequestDispatcher view = request.getRequestDispatcher("WEB-INF/jsp/versions.jsp");
view.forward(request, response);
File WEB-INF/jsp/versions.jsp contains these lines:
<div id="content">
<jsp:include page="/WEB-INF/jspf/organization-filter.jspf" />
...
</div>
File /WEB-INF/jspf/organization-filter.jspf contains these lines:
<form name="organization-filter" action="versions">
<input type="text" id="org_name" name="org_name" value="<%= request.getAttribute("org_name") %>">
<br>
<input type="hidden" id="org_id" name="org_id" value="<%= request.getAttribute("org_id") %>">
<br>
<input type="submit" name="submit" value="Submit"/>
</form>
When I open page /versions (mapped to the servlet above) it seems that organization-filter.jspf is not compiled because instead of blank input field named org_name I can see this text inside it:
<%= request.getAttribute(
If I change include directive in the versions.jsp like shown below it starts working:
<div id="content">
<%@include file="/WEB-INF/jspf/organization-filter.jspf" %>
...
</div>
Please advise why it doesn’t work when I use jsp:include. Thank you in advance. Vojtech
A jspf file is a file that is supposed to be statically included, using an include directive:
That’s just what a JSP
fragmentsegment is, and since it’s supposed tobe statically included, there is no point in compiling it.Here’s what the spec says:
If you want to dynamically include it, then it must have the
.jspextension. But in this case, I don’t see why you wouldn’t use a static include.