Standard actions
They are used for performing an action during request processing phase of JSP life cycle.
JSP Actions
JSP Actions lets you perform some action.
Directives vs. Actions
- Directives are used during translation phase while actions are used during request processing phase.
- Unlike Directives Actions are re-evaluated each time the page is accessed.
The following are the action elements used in JSP:
1. <jsp:include>
Used to include one JSP or html inside another JSP.
<jsp:includepage="page URL" /> <html> <head> <title>Demo of JSP include Action Tag</title> </head> <body> <h3>JSP page: Demo Include</h3> <jsp:includepage="sample.jsp"flush="false"/> </body> </html>
2. <jsp:forward>
Used to forward the request from one JSP to another JSP.
<jsp:forwardpage="URL of the another static, JSP OR Servlet page"/>
<html> <head> <title>Demo of JSP Forward Action Tag</title> </head> <body> <h3>JSP page: Demo forward</h3> <jsp:forwardpage="second.jsp"/> </body> </html>
3. <jsp:param>
Used to pass the parameters from one jsp to another jsp
<jsp: paramname="param_name_here"value="value_of_parameter_here"/>
<html> <head> <title>Demo of JSP Param Action Tag</title> </head> <body> <h3>JSP page: Demo Param along with forward</h3> <jsp:forwardpage="second.jsp"> <jsp:paramname="date"value="20-05-2012"/> <jsp:paramname="time"value="10:15AM"/> <jsp:paramname="data"value="ABC"/> </jsp:forward> </body> </html>
second.jspDate:
<%=request.getParameter("date")%> Time:<%=request.getParameter("time")%> MyData:<%=request.getParameter("data")%>
4. <jsp:useBean>
Used to useJava Beans in a JSP page, through this tag you can easily invoke a bean.
<jsp: useBeanid="bean instance name" class="fully qualified class name"scope="some scope" type="type casting"/>
5. <jsp:setProperty>
Used to assign the value to the properties of the java bean class.
<jsp:setPropertyname="bean instance name"property="java bean class property"param="request parameter value" value="any value"/>
6. <jsp:getProperty>
Used to get the value of the properties from the java bean class.
<jsp:getPropertyname="bean instance name"property="java bean class property"/>
example
PersonTO
public class PersonTO { private String firstname; private String lastname; private String email; //getters and setters }
login.html
<html> <head> </head> <body> <formaction="../jsp/userDetail.jsp"method="get"> <tableborder="2"> <tr> <td>Enter your first name</td> <td><inputtype="text"name="firstname"></td> </tr> <tr> <td>Enter your last name</td> <td><inputtype="text"name="lastname"></td> </tr> <tr> <td>Enter your Email</td> <td><inputtype="text"name="email"></td> </tr> <tr> <tdcolspan="2"align="center"> <inputtype="submit"value="click here"></td> </tr> </table> </form> </body> </html>
userDetail.jsp
<html> <body> <jsp:useBeanid="pto"class="in.com.pradeepit.jsp.usebean.PersonTO"> <jsp:setPropertyname="pto"property="*"/> </jsp:useBean> <h4>Your first Name is <jsp:getPropertyname="pto"property="firstname"/></h4> <h4>Your Last Name is <jsp:getPropertyname="pto"property="lastname"/></h4> <h4>Your Email is <jsp:getPropertyname="pto"property="email"/></h4> </body> </html>
0 responses on "3.3 Standard actions"