JSP Action :
To talk on JSP action , it can be defined as components that are used to construct XML syntax to control the
behavior of the servlet engine. These components can be used for dynamically inserting of a file, reuse
JavaBeans components, forward the user to another page, or generate HTML for
the Java plugin.
The syntax for the Action element, as it
conforms to the XML standard:
<jsp:action_name attribute="value" />
Action elements are predefined functions and there
are following JSP actions available in JSP:
Syntax
|
Purpose
|
jsp:include
|
It includes a file at the time the page is requested
|
jsp:useBean
|
It finds or instantiates a JavaBean
|
jsp:setProperty
|
This sets the property of a JavaBean
|
jsp:getProperty
|
This inserts the property of a JavaBean into the output
|
jsp:forward
|
This forwards the requester to a new page
|
jsp:plugin
|
Generates browser-specific code that makes an OBJECT or
EMBED tag for the Java plugin
|
jsp:element
|
It defines XML elements dynamically.
|
jsp:attribute
|
This defines dynamically defined XML element's attribute.
|
jsp:body
|
Defines dynamically defined XML element's body.
|
jsp:text
|
Use to write template text in JSP pages and documents.
|
Common Attributes:
There are two common attributes that are used for all Action
elements: the id attribute and the scope attribute.
- Id attribute: This attribute uniquely identifies the Action element, and it allows the action to be referenced inside the JSP page. If the Action creates an instance of an object the id value can be used to reference it through the implicit object PageContext.
- Scope attribute: This attribute identifies the lifecycle of the Action element. The id attribute and the scope attribute are directly related, as the scope attribute determines the lifespan of the object associated with the id. The scope attribute has four possible values: (a) page, (b) request, (c)session, and (d) application.
Example:
JSP File (index.jsp)
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Nirajanghimirey.blogspot.com</title>
</head>
<body>
<center>
<h2>This is the example of action.</h2>
<jsp:include page="link.jsp" flush="true" />
</center>
</body>
</html>
JSP File (link.jsp)
<p>Current Time: <%= (new java.util.Date()).toLocaleString()%></p>
No comments:
Post a Comment