0% found this document useful (0 votes)
137 views5 pages

5.JSP Directives

The document discusses the different scopes available in JSP technology to make data available to multiple resources: 1. Page scope - Data is available only within the current JSP page. 2. Request scope - Data is available to all resources requested by the current request. 3. Session scope - Data is available to all resources requested by the current client's session. 4. Application scope - Data is available to all resources within the entire web application. An example application is provided to demonstrate passing form data between an HTML page and JSP page using request scope.

Uploaded by

kasim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views5 pages

5.JSP Directives

The document discusses the different scopes available in JSP technology to make data available to multiple resources: 1. Page scope - Data is available only within the current JSP page. 2. Request scope - Data is available to all resources requested by the current request. 3. Session scope - Data is available to all resources requested by the current client's session. 4. Application scope - Data is available to all resources within the entire web application. An example application is provided to demonstrate passing form data between an HTML page and JSP page using request scope.

Uploaded by

kasim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

nd

DURGASOFT, # 202,2 Floor,HUDAMaitrivanam,Ameerpet, Hyderabad - 500038,  040 – 64 51 27 86,


80 96 96 96 96, 9246212143 | www.durgasoft.com
JSP Scopes

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

Jsp1Jsp Jsp2 Jsp3 Jsp4


Jsp1 Jsp1
Jsp2 forward forward jsp2
Jsp3
include include Jsp4
session

session

page page page page

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

have the scope upto the present Jsp page.

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

You might also like