Example & Tutorial understanding programming in easy ways.

What is action tag in jsp? explain with example?.

JSP provides a bunch of standard action tags that we can use for specific tasks such as working with java bean objects, including other resource, forward the request to other resource etc.

The following is the list of Standard Actions in JSP.              

                      JSP Action                        Description
jsp:getProperty To get the property of a java bean, used with jsp:useBean action.
jsp:useBean To get the java bean object from given scope or to create a new object of java bean.
jsp:setProperty  To set the property of a java bean object, used with jsp:useBean action.
jsp:include To include a resource at runtime, can be HTML, JSP or any other file
jsp:body            
 
  To define the dynamically generated XML element body
jsp:forward   To forward the request to another resource.
jsp:text                
 
To write template text in JSP page.
jsp:element     To define the XML elements dynamically.
jsp:attribute         To define the dynamically generated XML element attributes
 
jsp:plugin    To generate the browser-specific code that makes an OBJECT or EMBED tag for the Java plugin.

 

Some important action tags with example here...

example: jsp forword action

<html>

<body>

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

</body>

<html>

In the above exampe we use the Standard Tag "<jsp:forward page" to redirect to the "pass.jsp" page.

example: jsp include action

Like include page directive this action is also used to insert a JSP file in another file.

syntax:

<jsp:include page="page URL" flush="Boolean Value" />

Example:

<html>  <head>

<title>Demo of JSP include Action Tag</title>

</head><body>

<h3>JSP page: Demo Include</h3>

<jsp:include page="test.jsp" flush="false" />

</body></html>

Read More →