Stage 2 · Topic 2 - JSP · Session 2: Action Elements
<%@ include %>directive |
<jsp:include>action |
<jsp:forward>action |
|
|---|---|---|---|
| When it runs | once, at translation time (the first time the page is compiled) | on every request | on every request |
| Output of the calling page | kept, with the fragment pasted into it | kept, with the fragment's output merged in | discarded — only the target's output is sent |
| Address bar | unchanged | unchanged | unchanged (the browser is never told) |
| Can add parameters | no | yes, with <jsp:param> |
yes, with <jsp:param> |
| Variable names collide? | yes — a local variable declared in both files is a duplicate-definition compile error | no — the two pages are compiled separately | no |
| Best for | static HTML fragments: header, footer, menu | dynamic fragments, servlets, templates | the "entry page" pattern: index.jsp decides which
real page to show, e.g. after a login |
| Action | Purpose |
|---|---|
jsp:forward | forward the request and response to another resource |
jsp:include | include another resource |
jsp:useBean | create or locate a bean object |
jsp:setProperty | set the value of a property in a bean object |
jsp:getProperty | print the value of a property of a bean |
jsp:param | set a parameter for forward or include |
jsp:plugin | embed a component such as an applet — removed from the JSP specification, see below |
jsp:fallback | print a message if the plugin is not working — removed, see below |
<jsp:plugin type="applet" code="MouseDrag.class"/>.
Both jsp:plugin and jsp:fallback were
deprecated in JSP 2.0 and removed, Java applets have been removed
from the JDK, and no modern browser supports them. The tag is no longer
part of the specification, so it is deliberately not reproduced
here — a page using it fails to compile on Tomcat 9.
isThreadSafe attribute (Session 1, slide 21) and the
manual copying of JSTL jars into Tomcat's directories (Session 5).