pages and is also used to enable the use of server side JavaBeans. Instead of
using
either link to a
properties.
There are so many action tags available for
The most commonly used action tags are three of them that are:
- include
- forward
- useBean
include directive. The include tag
is used to include either static or dynamic content, wherever required.
expression %>}" flush="true" />
If the file is dynamic one can use the syntax as below:
<jsp:include page="{relativeURL | <%= expression %>}" flush="true" /> <jsp:param name="parameterName" value="{parameterValue
| <%= expression %>}" />
For example: An example to include a static file jsp-directives.html
in the include action tag:
<jsp:include page="jsp-directives.html"flush="true"/>
Let us see an example of dynamic file inclusion in the include action tagwhich is done as below:
<jsp:include page="test/jsp-directives.html.jsp"><jsp:include name="username" value="sandeep" />
</jsp:include>
2. Forward Action Tag:- The forward action tag is used to transfer
control to a static or dynamic resource. The static or dynamic resource to which
control has to be transferred is represented as a URL. The user can have the
target file as an HTML file, another JSP file, or a servlet. Any of the above is
permitted.
<jsp:forward page="{relativeURL | <%= expression %>}" />
Now another representation for forward action Tag is as:
<jsp:forward page ="{relativeURL | <%= expression %>}" /> <jsp:param name ="parameterName" value="parameterValue"
| <%= expression %>}" />
3. useBean Action Tag:- The useBean action tag is the most commonly
used tag because of its powerful features. It allows a JSP to create an instance
or receive an instance of a Java Bean. It is used for creating or instantiating
a bean with a specific name and scope. This is first performed by locating the
instance of the bean.
<jsp:useBean id="beanInstanceName" scope="page|request|session|application"
class="package.class" | type="package.class"
|
beanName="{package.class | <%=
expression %>}"
}
{ /> |> other elements
</jsp:useBean>}
There are the several attributes available in useBean Action Tag, that is:
- id: This refers to a variable that is case sensitive, identifying
the bean within scope attribute defined. - scope: This refers to the scope of the existence of bean. The
default scope is page. - class: The class name is mentioned and using this bean is
Instantiated. The data type to which bean must be assigned is mentioned in
type. - beanName: When this is specified, the bean is instantiated by the
java.beans.Beans.instantiate method.
No comments:
Post a Comment