In this section, we will learn about JSP standard Action & their elements with some examples.
In this section, we will learn about JSP standard Action & their elements with some examples.In this section, we will learn about JSP standard Action & their elements with some examples.
JSP Standard action are predefined tags which perform some action based on information that is required at the exact time the JSP page is requested by a browser. An action can, for instance, access parameters sent with the request to do a database lookup. It can also dynamically generate HTML, such as a table filled with information retrieved from an external system. They can be used to include a file at the request time, to find or instantiate a JavaBean, to forward a request to a new page, to generate a browser-specific code, etc. The JSP standard actions affect the overall runtime behavior of a JSP page and also the response sent back to the client.
Given below some action elements :
Action element | Description |
<jsp:useBean> |
Makes a JavaBeans component available in a page |
<jsp:getProperty> |
Gets a property value from a JavaBeans component and adds it to the response |
<jsp:setProperty> |
Sets a JavaBeans component property value |
<jsp:include> |
Includes the response from a servlet or JSP page during the request processing phase |
<jsp:forward> |
Forwards the processing of a request to servlet or JSP page |
<jsp:param> |
Adds a parameter value to a request handed off to another
servlet or JSP page using <jsp:include> or <jsp:forward> |
<jsp:plugin> |
Generates HTML that contains the appropriate
browser-dependent elements (OBJECT or EMBED) needed to execute an applet with the Java Plug-in software |
<jsp:include> :
Instead of loading the text of the included file in the original file like "include directive", it actually calls the included target at run-time (the way a browser would call the included target. In practice, this is actually a simulated request rather than a full round-trip between the browser and the server). Following is an example of jsp:include usage :
includestandardaction.jsp
<HTML> <BODY> Going to include hello.jsp...<BR> <jsp:include page="hello.jsp"/> </BODY> </HTML>
|
OUTPUT:
<jsp:forward> :
The <jsp:forward> element forwards the request object containing the client request information from one JSP file to another file. The target file can be an HTML file, another JSP file, or a servlet, as long as it is in the same application context as the forwarding JSP file. The lines in the source JSP file the <jsp:forward> element are not processed.
This sample code shows the use of
<html> <% double freeMemory = Runtime.getRuntime().freeMemory(); double totalMemory = Runtime.getRuntime().totalMemory(); double percent = freeMemory/totalMemory; if(percent<0.5){ %> <jsp:forward page="one.jsp"/> <%}else{%> <jsp:forward page="two.html"/> <%}%> </html>
|
one.jsp
<html> <body> <font color="red"> VM Memory usage less than 50 percent </font> </body> </html>
|
two.jsp
<html> <body> <font color="red"> VM Memory usage greater than 50 percent </font> </body> </html>
|
OUTPUT :