Setup Menus in Admin Panel

3.3 Standard actions

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

  1. Directives are used during translation phase while actions are used during request processing phase.
  2. 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>

 

January 16, 2016

0 responses on "3.3 Standard actions"

Leave a Message

Your email address will not be published. Required fields are marked *

About Us

Pradeep Academy is an online & Training institute To make learning easy, interesting, affordable and accessible to millions of learners across the Globe. To create an alternative learning platform, using a unique learning methodology of live online interactive courses along with 24x7 support. We aim to empower our customers with skills which will help them get an edge in their careers and improve their lives.

Contact Us

Address :

PradeepIT Consulting Services Pvt Ltd

205,Brigade gardens, No.19 Church Street , Bangalore – 560001, Karnataka, India

Email : [email protected]
Ph No: 08047363377
Web: https://academy.pradeepit.com
top
© Pradeep Academy.  Design & Developed by