JSP Standard Action :
JSP actions allow you to insert a file dynamically, reuse external JavaBean components, forward the request to the other page and generate HTML.
SN | Syntax | Use |
---|---|---|
1 | jsp:include | Includes a file at the time the page is requested |
2 | jsp:forward | Forwards the requester to a new page |
3 | jsp:param | To pass the parameter from one JSP to another JSP |
4 | jsp:useBean | For using java beans in JSP |
5 | jsp:setProperty | Sets the property of a JavaBean |
6 | jsp:getProperty | Gets the property of a JavaBean |
jsp:include action :
JSP include action allows you to include a file at runtime. The syntax of jsp include action is as follows:
<jsp:include page="some jsp or html"/>
JSP actions allow you to insert a file dynamically, reuse external JavaBean components, forward the request to the other page and generate HTML.
SN | Syntax | Use |
---|---|---|
1 | jsp:include | Includes a file at the time the page is requested |
2 | jsp:forward | Forwards the requester to a new page |
3 | jsp:param | To pass the parameter from one JSP to another JSP |
4 | jsp:useBean | For using java beans in JSP |
5 | jsp:setProperty | Sets the property of a JavaBean |
6 | jsp:getProperty | Gets the property of a JavaBean |
jsp:include action :
JSP include action allows you to include a file at runtime. The syntax of jsp include action is as follows:
<jsp:include page="some jsp or html"/>
Following is an example of jsp:include usage. Let us define following two files index.jsp and header.jsp as follows:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Index Page</title> </head> <body> <jsp:include page="header.jsp"/> <h2>Header part is in different file</h2> </body> </html>
header.jsp
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>header file</title> </head> <body> <h2>This is header file</h2> </body> </html>
Browser Output :
In the above example we are including header.jsp into index.jsp by using jsp:include action.
jsp:forward action :
jsp:forward action allows you to forward a request to the other page. The syntax of the jsp:forward action is given below.Attribute of forward action is page which value should be page you want to forward the request. You can specify the page either statically or dynamically by using expression.
<jsp:forward page="error.jsp" /> or <jsp:forward page="<%= java-expression %>" />
Example :
index.jsp
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>forward example</title> </head> <body> <h2> This is jsp forward tag example..</h2> <jsp:forward page="info.jsp"/> </body> </html>
info.jsp
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <h1>Welcome to info page...</h1> </body> </html>
In the above example we are forwarding request from index.jsp to info.jsp.
jsp:param tag :
jsp:param tag is used to pass the parameters when you are forwarding the request from one jsp to another JSP or while including one JSP to another JSP.
Example :
index.jsp
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <jsp:forward page="info.jsp"> <jsp:param name="name" value="Mukesh"/> <jsp:param name="sid" value="99"/> </jsp:forward> </body> </html>
info.jsp
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> Welcome <%= request.getParameter("name")%> <br> Your SID is <%= request.getParameter("sid")%> </body> </html>
In the above example we are forwarding request from index.jsp to info.jsp with parameter name and SID
In next article we will discuss about jsp:useBean tagRelated Articles