5.JSP Directives
5.JSP Directives
In J2SE applications, to define data availability i.e. scope for we have to use access
specifierspublic, protected, default and private.
Similarly to make available data to number of resources Jsp technology has provided the
following 4 types of scopes with the access modifiers.
Client
App1 Client
session
request request
application
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com
1. Page Scope:
If we declare the data in page scope by using pageContext object then that data should
2. Request Scope:
If we declare the data in request object then that data should have the scope up to the
number of resources which are visited by the present request object.
3. Session Scope:
If we declare the data in HttpSession object then that data should have the scope up to
the number of resources which are visited by the present client.
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com
4. Application Scope:
If we declare the data in ServletContext object then that data should have the scope up
to the number of resources which are available in the present web application.
--------------Application1---------------
App1:
employeedetails.html:
<html>
<body bgcolor="lightblue"><br><br><br><br>
<center><h1>Employee Details Form</h1></center>
<pre><h2>
<form method="get" action="display.jsp">
Employee Id :<input type="text" name="eid"/>
Employee Name : <input type="text" name="ename"/>
Employee Salary : <input type="text" name="esal"/>
<input type="submit" value="Display"/>
</h2></pre>
</body>
</html>
display.jsp:
<%!
int eid;
String ename;
float esal;
%>
<%
try {
eid=Integer.parseInt(request.getParameter("eid"));
String ename=request.getParameter("ename");
float esal=Float.parseFloat(request.getParameter("esal"));
}
catch(Exception e){
e.printStackTrace();
}
%>
<html>
<body>
<center><h1>Employee Details</h1></center>
<center>
Employee Id : <%=eid %><br><br>
Employee Name : <%=ename %><br><br>
Employee Salary : <%=esal %><br><br>
</center>
</body>
</html>
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com
nd
DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038, 040 – 64 51 27 86,
80 96 96 96 96, 9246212143 | www.durgasoft.com