JSP Actions
We’ll take a look at JSP actions in this tutorial. JSP actions are xml-tags that can be used within a JSP. They’ll call standard webserver functionality. We’ve already used one of them: jsp:useBean.
Here’s a list of all the JSP actions out there:
- jsp:useBean: this defines a Bean inside a JSP
- jsp:forward: this jsp action is used to forward to another page, it’s possible to set some parameters for the next page
- jsp:include: this jsp action is used to include another page, just like with the forward tag it’s possible to set some parameters
- jsp:param: we can set parameters with this jsp action, so it can be used with the jsp:forward and jsp:include actions
- jsp:fallback: if you want to have applets on your jsp but the browser doesn’t support it, this jsp action is used to define what will happen next
- jsp:plugin: this jsp action creates the right html-tags to run an applet in your jsp
- jsp:getProperty: get the value of a property from a bean
- jsp:setProperty: set the value of a property from a bean
We’ve already handled the useBean action, so we’ll skip that one. We’ll look at two other actions though:
<jsp:forward page="nextpage.jsp"> <jsp:param name="from" value="current.jsp" /> </jsp:forward>
This basically speaks for itself: we ask the jsp to forward to the next jsp, and give a parameter so the next jsp knows where the forward came from.
<jsp:include page="last10sales.jsp"> <jsp:param name="orderby" value="id" /> </jsp:include>
With the include tag we include a list of the last 10 sales, ordered by id. The last10sales jsp can read this parameter and use it to order.
The last 10 sales will be shown where the include-tag is called.