JSP Action Tags by R4R Team

JSP Action Tags:
There are many JSP action tags or elements. Each JSP action tag is used to perform some specific tasks.
The action tags are used to control the flow between pages and to use Java Bean. The Jsp action tags are given below.

JSP Action Tags  Description
jsp:forward forwards the request and response to another resource.
jsp:useBean creates or locates bean object.
jsp:include includes another resource.
jsp:setProperty sets the value of property in bean object.
jsp:getProperty prints the value of property of the bean.
jsp:plugin embeds another components such as applet.
jsp:param sets the parameter value. It is used in forward and include mostly.
jsp:fallback can be used to print the message if plugin is working. It is used in jsp:plugin.


note:The jsp:useBean, jsp:setProperty and jsp:getProperty tags are used for bean development. So we will see these tags in bean developement.Here we select only important JSP action tags.

jsp:forward action tag:

The jsp:forward action tag is used to forward the request to another resource it may be jsp, html or another resource.

Syntax of jsp:forward action tag without parameter

<jsp:forward page="relativeURL | <%= expression %>" />

Syntax of jsp:forward action tag with parameter

<jsp:forward page="relativeURL | <%= expression %>">

<jsp:param name="parametername" value="parametervalue | <%=expression%>" />

</jsp:forward>


Example: jsp:forward action tag without parameter

In this example, we are simply forwarding the request to the printdate.jsp file.

index.jsp
 

<html>

<body>

<h2>this is index page</h2>

<jsp:forward page="printdate.jsp" />

</body>

</html>

printdate.jsp

<html>

<body>

<% out.print("Today is:"+java.util.Calendar.getInstance().getTime()); %>

</body>

</html>

Example: jsp:forward action tag with parameter

In this example, we are forwarding the request to the printdate.jsp file with parameter and printdate.jsp file prints the parameter value with date and time.

index.jsp
 

<html>

<body>

<h2>this is index page</h2>

<jsp:forward page="printdate.jsp" >

<jsp:param name="name" value="ycd.com" />

</jsp:forward>

</body>

</html>

printdate.jsp

<html>

<body>

<% out.print("Today is:"+java.util.Calendar.getInstance().getTime()); %>

<%= request.getParameter("name") %>

</body>

</html>

 

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!