Introduction to Active Server Pages (ASP)
ASP.NET
Java Server Pages (JSP), JSP Processing
JSP Life Cycle, JSP Application Design
Tomcat Server, JSP Components: Scriptlets, Directives
JSP Actions
JSP Implicit Objects, Sharing Data between JSP Pages
Session Tracking
JSP Error Handling and Debugging
COM/DCOM
2. QIP-3
UNIT-IV
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Lecture Number Topic Description
Lecture-1 Introduction to Active Server Pages (ASP)
Lecture-2 ASP.NET
Lecture-3 Java Server Pages (JSP), JSP Processing
Lecture-4 JSP Life Cycle, JSP Application Design
Lecture-5 Tomcat Server, JSP Components: Scriptlets, Directives
Lecture-6 JSP Actions
Lecture-7 JSP Implicit Objects, Sharing Data between JSP Pages
Lecture-8 Session Tracking
Lecture-9 JSP Error Handling and Debugging
Lecture-10 COM/DCOM
3. Lecture No. 1
Active Server Pages (ASP)
What is ASP?
• ASP stands for Active Server Pages.
• ASP is a program that runs inside IIS.
• IIS stands for Internet Information Services.
• ASP is Microsoft’s solution to building advanced Web sites.
• ASP page can consist of the followings:
HTML Tags
Scripting Language (JavaScript/ VBScript)
ASP Built-in Objects
ActiveX components e.g.: ActiveX Data Object (ADO)
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
4. Lecture No. 1
ASP
Processing of an HTML Page
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
RequestBrowser Web Server
Memory-HTML fileHTML File
When a browser requests an HTML file, the server returns the file
5. Lecture No. 1
ASP
Processing of an HTML Page
Steps involved in HTML page Processing are:
1)A user enters request for Web Page in browser.
2) The browser sends the request for the web page to web server such as IIS.
3) The web server receives the request and recognizes that the request is for an
HTML file by examining the extension of the requested file (.Html or .htm )
4) The Web Server retrieves the proper HTML file from disk or memory and
sends the file back to the browser.
5) The HTML file is interpreted by the user’s browser and the results are
displayed in the browser window.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
6. Lecture No. 1
ASP
Processing of an ASP Page
When a browser requests an ASP file, IIS passes the request to the ASP engine.
The ASP engine reads the ASP file, line by line, and executes the scripts in the
file. Finally, the ASP file is returned to the browser as plain HTML.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
RequestBrowser Web Server
Memory-ASP FileHTML File Processing
7. Lecture No. 1
ASP
Processing of an ASP Page
Steps involved in ASP page Processing are:
1) A user enters request for Web Page in browser.
2) The browser sends the request for the web page to web server such as IIS.
3) The web server receives the request and recognizes that the request is for an
ASP file by examining the extension of the requested file (.asp)
4) The Web Server retrieves the proper ASP file from disk or memory.
5) The Web Server sends the file to a special program named ASP.dll
6) The ASP file is processed from top to bottom and converted to a Standard
HTML file by ASP.dll.
7) The HTML file is sent back to the browser.
8) The HTML file is interpreted by the user’s browser and the results are
displayed in the browser window.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
8. Lecture No. 1
ASP
Built-in Objects in ASP
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Objects Description
Application It is used to share data among several users visiting the
same group of pages. Only one instance of the Application
object is created per application, and it is shared among all
the clients accessing that application.
ASPError It allows you to obtain information about errors that have
occurred in the script.
ObjectContext It is used to link ASP and the Microsoft Transaction Server.
Request It is used to access data that the client sent when it
requested the current page
9. Lecture No. 1
ASP
Built-in Objects in ASP
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Objects Description
Response It is used to send output to the client. It also allows you to
control how and when the output is sent
Server Describes the methods and properties of the object that
provides methods for the sever tasks. With these methods
you can execute code, get error conditions, encode text
strings, create objects for use by the web page, and map
physical paths.
Session Describes the methods, properties, and collections of the
object that stores information related to user’s session,
including variables and objects that exist for the lifetime of
the session.
10. Lecture No. 2
ASP.NET
• ASP.NET is a development framework for building web pages and web sites
with HTML, CSS, JavaScript and server scripting
• ASP.NET is a new ASP generation. It is not compatible with Classic ASP, but
ASP.NET may include Classic ASP
• ASP.NET pages are compiled, which makes them faster than Classic ASP
• ASP.NET has better language support, a large set of user controls, XML-
based components, and integrated user authentication.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
11. Lecture No. 2
ASP.NET
• ASP.NET pages have the extension .aspx, and are normally written in VB
(Visual Basic) or C# (C sharp)
• User controls in ASP.NET can be written in different languages, including
C++ and Java
• When a browser requests an ASP.NET file, the ASP.NET engine reads the
file, compiles and executes the scripts in the file, and returns the result to the
browser as plain HTML.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
12. Lecture No. 2
ASP.NET
The MVC Programming Model
MVC is a framework for building web applications using a MVC (Model View
Controller) design:
• The Model represents the application core (for instance a list of database
records).
• The View displays the data (the database records).
• The Controller handles the input (to the database records)
The MVC model defines web applications with 3 logic layers:
The business layer (Model logic)
The display layer (View logic)
The input control (Controller logic)
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
13. Lecture No. 2
ASP.NET
The Model is the part of the application that handles the logic for the
application data.
Often model objects retrieve data (and store data) from a database.
The View is the parts of the application that handles the display of the data.
Most often the views are created from the model data.
The Controller is the part of the application that handles user interaction.
Typically controllers read data from a view, control user input, and send input
data to the model.
• The MVC separation helps you manage complex applications, because you
can focus on one aspect a time. For example, you can focus on the view
without depending on the business logic. It also makes it easier to test an
application.
• The MVC separation also simplifies group development. Different
developers can work on the view, the controller logic, and the business logic in
parallel.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
14. Lecture No. 2
ASP.NET
ASP.NET Built-in Objects
• Using ASP.NET built-in objects, you can access to information regarding the
Web server, the client who is accessing a Web page, the Web application that
contains the Web page and the fields in the HTTP request and response streams
• The Request, Response, Server, Application, and Session objects are part of
ASP.NET and are used in much the same way as they are in ASP. However, in
ASP.NET these objects are defined in new classes in the System.Web
namespace
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
15. Lecture No. 2
ASP.NET
ASP.NET Built-in Objects
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Objects Description
Application Describes the methods, properties, and collections of the
object that stores information related to the entire Web
application, including variables and objects that exist for the
lifetime of the application.
Request Describes the methods, properties, and collections of the
object that stores information related to the HTTP request.
This includes forms, cookies, etc.
Response Describes the methods, properties, and collections of the
object that stores information related to the server's response.
This includes displaying content, manipulating headers, etc.
16. Lecture No. 2
ASP.NET
ASP.NET Built-in Objects
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Objects Description
Server Describes the methods and properties of the object that
provides methods for various server tasks. With these methods
you can execute code, get error conditions, encode text strings,
create objects for use by the Web page, and map physical
paths.
Session Describes the methods, properties, and collections of the
object that stores information related to the user's session,
including variables and objects that exist for the lifetime of the
session.
17. Lecture No. 2
ASP V/s ASP.NET
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
ASP ASP.NET
ASP is interpreted language based on
scripting languages
ASP.NET is supported by compiler and
has compiled language support.
(VB.NET, C#)
ASP has mixed HTML and coding logic Separate code and design logic possible.
Limited development and debugging tools
available.
Variety of compilers and tools available
including the Visual Studio.Net 4.
Limited OOPS support. Completely object oriented.
Limited session and application state
management.
Complete session and application state
management
Poor Error handling system. Full proof error handling possible.
No in-built support for XML Full XML support for easy data exchange
No fully distributed data source support Fully distributed data source support.
18. Lecture No. 3
Java Server Pages (JSP)
• Java Server Pages (JSP) technology provides a simplified, fast way to create
web pages that display dynamically-generated content.
• A JSP page is a page created by the web developer that includes JSP
technology-specific tags, declarations, and possibly scriptlets, in combination
with other static HTML or XML tags.
• A JSP page has the extension .jsp; this signals to the web server that the JSP
engine will process elements on this page.
• Pages built using JSP technology are typically implemented using a
translation phase that is performed once, the first time the page is called. The
page is compiled into a Java Servlet class and remains in server memory, so
subsequent calls to the page have very fast response times.
Subject Code and Name @ Vidya College of Engineering, Meerut
19. Lecture No. 3
JSP
Reasons to use JSP
• Multiplatform
• Component reuse by using Java beans and EJB.
• Advantages of Java.
• Dynamic content can be served in a variety of formats.
• Recommended web access layer for n-tier architecture
• Completely leverages the Servlet API
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
20. Lecture No. 3
JSP
JSP Page Structure
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
JSP Page
Directives Scripting
Elements
Actions
Standard
Actions
Custom
Actions
Template Text
Example
<html>
<body>
<%
out.println(“Hello World”);
%>
</body>
</html>
21. Lecture No. 3
JSP Processing
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Processing phase
Translation phase
Client Server
Request
Response
Hello.jsp
helloServlet.class
helloServlet.java
Read
Generate
Execute
22. Lecture No. 3
JSP Processing
1. Web browser send JSP request
2. JSP request send via Internet to the web server
3. The web server send the JSP file (template pages) to JSP servlet engine
4. Parse JSP file
5. Generate servlet source code
6. Compile servlet to class
7. Instantiate servlet
Finally web browser handles the dynamically generated HTML page inside the
HTTP response exactly as if it were a static page.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
23. Lecture No. 3
JSP Processing
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
24. Lecture No. 4
JSP Life Cycle
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
jspInit()
jspDestroy()
jspService()
Init Event
Request
Response
Destroy Event
25. Lecture No. 4
JSP Life Cycle
The following are the paths followed by JSP
Compilation
If the page has never been compiled, or if the JSP has been modified since it
was last compiled, the JSP engine compiles the page.
The compilation process involves three steps:
Parsing the JSP
Turning the JSP into a servlet.
Compiling the servlet.
Initialization
When a container loads a JSP, it invokes the jspinit() method before servicing
any requests.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
26. Lecture No. 4
JSP Life Cycle
Execution
Whenever a browser requests a JSP and the page has been loaded and
initialized, the JSP engine invokes the jspService() method in the JSP.
Clean up
The destruction phase of JSP life cycle represents when a JSP is being
removed from use by a container.
The jspDestroy() method is the JSP equivalent of the destroy method for
servlets.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
27. Lecture No. 4
JSP Application Design
Model-1 Architecture
Each JSP page is entrusted to deal with its request entirely by itself
Thereby generating a response and sending it back to the client.
For this reason its often known as page-centric
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
JSP/ Servlet Container Data Tier
JSP Page
Java Bean
Request
Response
Data
Data
28. Lecture No. 4
JSP Application Design
Problems with Model-1 Architecture
Maintainability Problems
Reusability Problems
Security Problems
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
29. Lecture No. 4
JSP Application Design
Model-2 Architecture
It is a server side implementation of popular MVC design pattern.
Separation of the way application data is modeled (The Model) from
the way its presented (The View) and it also requires a separate
component to handle the processing in between (The Controller).
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
JSP/ Servlet Container Data Tier
Servlet
(Controller)
Java
Bean
(Model)
Request
Response
Data
Data
JSP
(View)
30. Lecture No. 4
JSP Application Design
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Public class MySelect {
public void doGet(…){
if (isValid(..){
saveRecord();
out.println(“<html>”);
….
}
}
private void isValid(…){…}
private void saveRecord(…) {…}
}
Servlet
JSP
JavaBeans
Process request
Presentation
Business logic
controller
view
model
Model-View-Controller (MVC) design
31. Lecture No. 5
Tomcat Server
Apache Tomcat is an open-source web server and servlet container
developed by Apache Software Foundation (ASF).
Tomcat implements several Java EE specifications including Java Servlet,
Java Server Pages (JSP) etc. and provides a pure java HTTP web server
environment for Java code to run in.
Tomcat can be used as either a standalone product with its own internal Web
server or together with other Web servers, including Apache, Netscape
Enterprise Server, Microsoft Internet Information Server (IIS), and
Microsoft Personal Web Server.
Tomcat requires a Java Runtime Enterprise Environment that conforms to
JRE 1.1 or later
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
32. Lecture No. 5
JSP Components
There are three main types of JSP constructs that you embed in a page:
Scripting elements
• You can specify Java code
• Expressions, Scriptlets, Declarations
Directives
• Let you control the overall structure of the servlet
• Page, include, Tag library
Actions
• Enable the use of server side Java Beans
• Transfer control between pages
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
33. Lecture No. 5
JSP Scripting Elements
You can insert code into the servlet that will be generated from the JSP page.
Expressions: <%= expression %>
Evaluated and inserted into the servlet’s output. i.e., results in something
like out.println(expression)
e.g.: <%= new java.util.Date() %>
Scriptlets: <% code %>
Inserted verbatim into the servlet’s _jspService method (called by service)
e.g.: <% int x = 5; %>
Declarations: <%! code %>
Inserted verbatim into the body of the servlet class, outside of any existing
methods
e.g.: <%!
public void jspDestroy() {
System.out.println(“JSP Destroyed”);
}
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
34. Lecture No. 5
JSP Directives
There are three types of directive tag:
Page Directive
Include Directive
Taglib Directive (Tag Library)
Page Directive
Defines page-dependent attributes, such as scripting language, error page and
buffering requirements.
e.g.:
<%@ page attribute1=“value1” attribute2=“value2” …. %>
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
35. Lecture No. 5
JSP Directives
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Attribute Purpose
contentType Defines the character encoding scheme.
errorPage Defines the URL of another JSP that reports on Java unchecked runtime
exceptions.
isErrorPage Indicates if this JSP page is a URL specified by another JSP page’s
errorPage attribute.
extends Specifies a superclass that the generated servlet must extend.
import Specifies a list of packages or classes for use in the JSP as the Java
import statement does for Java classes.
language Defines the programming language used in the JSP page
session Specifies whether or not the JSP page participates in HTTP sessions.
36. Lecture No. 5
JSP Directives
Page Directive example
<%@
page language=“java”
buffer=“10kb”
autoflush=“true”
errorPage=“/error.jsp”
import=“java.util.*, javax.sql.RowSet”
%>
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
37. Lecture No. 5
JSP Directives
Include Directive
The include directive enables JSP page developers to include the contents of
other files in the current JSP page.
e.g.: <%@ include file=“relative URL”%>
Example
<%@ include file=“header.html” %>
<%
out.println(“<body>”);
//other content
%>
<%@ include file=“footer.html” %>
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
38. Lecture No. 5
JSP Directives
Taglib Directive
The Taglib directive declares that your JSP page uses a set of custom tags,
identifies the location of the library, and provides a means for identifying the
custom tags in your JSP page.
e.g.: <%@ taglib uri=“relative URL” prefix=“prefix of tag” %>
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
39. Lecture No. 6
JSP Actions
Processed during the request processing phase.
As opposed to JSP directives which are processed during translation
Standard actions should be supported by J2EE compliant web servers.
Custom actions can be created using tag libraries
The different actions are:
Include Action
Forward Action
Param Action
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
40. Lecture No. 6
JSP Actions
useBean Action
getProperty Action
setProperty Action
plugin Action
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
41. Lecture No. 6
JSP Actions
Include Action
Include action used for including resources in a JSP page
Include directive includes resources in a JSP page at translation time
Include action includes response of a resource into the response of the JSP
page
Same as including resources using RequestDispatcher interface
Changes in the included resource reflected while accessing the page.
Normally used for including dynamic resources
Example
<jsp:include page=“inlcudedPage.jsp”>
Includes the output of includedPage.jsp into the page where this is
included.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
42. Lecture No. 6
JSP Actions
Forward Action
Forwards the response to other web specification resources
Same as forwarding to resources using RequestDispatcher interface
Forwarded only when content is not committed to other web application
resources
Otherwise an IllegalStateException is thrown
Can be avoided by setting a high buffer size for the forwarding jsp page
Example
<jsp:forward page=“Forwarded.html”>
Forwards the request to Forwarded.html
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
43. Lecture No. 6
JSP Actions
Param Action
Used in conjunction with Include & Forward actions to include additional
request parameters to the included or forwarded resource
Example
<jsp:forward page=“Param2.jsp”>
<jsp:param name=“FirstName” value=“Sanjay”>
</jsp:forward>
This will result in the forwarded resource having an additional parameter
FirstName with a value of Sanjay.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
44. Lecture No. 6
JSP Actions
useBean Action
Creates or finds a Java object with the defined scope.
Object is also available in the current JSP as a scripting variable
Syntax
<jsp:useBean id=“name” scope=“page | request | session | application”
class=“className” type=“typeName” | bean=“beanName” type=“typeName” |
type=“typeName” />
At least one of the type and class attributes must be present
We can’t specify values for both the class and bean name
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Example
<jsp:useBean id=“myName” scope=“request” class=“java.lang.String”>
<% firstName=“Sanjay”; %>
</jsp:useBean>
45. Lecture No. 6
JSP Actions
getProperty Action
getProperty is used in conjunction with useBean to get property values of the
bean defined by the useBean action.
Example
<jsp:getProperty name=“myBean” property=“firstName” />
Name corresponds to the id value in the useBean
Property refers to the name of the bean property
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
46. Lecture No. 6
JSP Actions
setProperty Action
setProperty is used to set bean properties.
Example
<jsp:setProperty name=“myBean” property=“firstName”
value=“Sanjay”/>
Sets the name property of myBean to SanjayExample (setProperty)
<jsp:setProperty name=“myBean” property=“firstName”
param=“fname”/>
Sets the name property of myBean to the request parameter fname
<jsp:setProperty name=“myBean” property=“*”>
Sets property to the corresponding value in request
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
47. Lecture No. 6
JSP Actions
plugin Action
Enables the JSP container to render appropriate HTML (based on the browser
type) to:
Initiate the download of the Java plugin
Execution of the specified applet or bean
plugIn standard action allows the applet to be embedded in a browser neutral
fashion
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Example
<jsp: plugin type=“applet” code=“MyApplet.class” codebase=“/”>
<jsp:params>
<jsp:param name=“myParam” value=“122”/>
</jsp:params>
<jsp:fallback><b>Unable to load applet</b></jsp:fallback>
</jsp:plugin>
48. Lecture No. 7
JSP Implicit Objects
Although scriptlets, expressions, and HTML template data are all
incorporated into the _jspService() method, the JSP container write the
skeleton of the method itself, initializing the page context and several useful
variables.
These variables are implicitly available inside scriptlets and expressions,
called as implicit objects.
They can be accessed like any other variable, but they don not have to be
declared first.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
49. Lecture No. 7
JSP Implicit Objects
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Variable Name Description
request The ServletRequest or HttpServletRequest being serviced. Each
time a client requests a page the JSP engine creates a new object to
represent that request.
response The ServletResponse or HttpServletResponse that will receive the
generated HTML output.
pageContext The pageContext object is used to represent the entire JSP page.
This object is a central repository for attribute data for the page,
request, session and application.
session If the JSP page uses an HttpSession, it is available here under the
name session. This object is used to track client session between
client requests.
application The servlet context object. This object is a representation of the
JSP page through its entire life cycle.
50. Lecture No. 7
JSP Implicit Objects
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Variable Name Description
out The character output stream used to generate the output HTML.
config The ServletConfig object for this servlet context. This object allows
the JSP programmer access to servlet or JSP engine initialization
parameters such as the paths or file locations etc.
page A reference to the JSP page itself.
exception An uncaught exception that causes the error page to be invoked.
This variable is available only to pages with isErrorPage=“true”
51. Lecture No. 7
Sharing Data between JSP Pages
Any real application consists of more than a single page, and multiple pages
often need access to the same information and server-side resources.
When multiple pages are used to process the same request, for instance one
page that retrieves the data the user asked for and another that displays it, there
must be a way to pass data from one page to another.
In an application in which the user is asked to provide information in
multiple steps, such as an online shopping application, there must be a way to
collect the information received with each request and get access to the
complete set when the user is ready.
Other information and resources need to be shared among multiple pages,
requests, and all users. Examples are information about currently logged-in
users, database connection pool objects, and cache objects to avoid frequent
database lookups
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
52. Lecture No. 1 (font size 28)
Sharing Data between JSP Pages
To share data, you should need to know how to:
Structure a JSP Application.
Pass control from one JSP page to another page.
Pass data from one JSP page to another page.
Example
A shopping application that accepts a users payment details on a form, validates the
details and displays a confirmation page or error depending upon user input
Various ways that JSP pages for collection of payment details can be structured. Can
even have everything on a single JSP page (messy for anything but simplest apps)
Have used 3 JSP pages:
payment details on a form(userinput.jsp)
validation of the details (validateinfo.jsp)
display of a confirmation page (confirmed.jsp) or error (userinput.jsp)
depending upon user input
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
53. Lecture No. 8
JSP Session Tracking
HTTP is a "stateless" protocol which means each time a client retrieves a Web
page, the client opens a separate connection to the Web server and the server
automatically does not keep any record of previous client request. You can
accomplish this on two basic ways:
Have the client remember all session related data and send it back to the server
as needed.
Have the server maintain all the data, assign an identifier to it and have the
clients remember the identifier.
Four techniques are commonly used:
Cookies
Hidden From Fields
URL Rewriting
The Http Session API
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
54. Lecture No. 8
JSP Session Tracking
Cookies
A web server can assign a unique session ID as a cookie to each web client and
for subsequent requests from the client they can be recognized using the received
cookie.
Along with the name and value, the cookie may contain:
An expiration date, after which the client is no longer expected to retain the
cookie. If no date is specified, the cookie expires as soon as the browser
session ends.
A domain name, such as servername.com, which restricts the subset of
URLs for which the cookie is valid. If unspecified, the cookie is returned
with all requests to the originating web server.
A path name that further restricts the URL subset.
A secure attribute, which, if present, indicates that the cookie should be
returned only if the connection uses a secure channel, such as SSL.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
55. Lecture No. 8
JSP Session Tracking
Hidden Form Fields
A web server can send a hidden HTML form field along with a unique session
ID as follows:
<input type="hidden" name="sessionid" value="12345">
This entry means that, when the form is submitted, the specified name and
value are automatically included in the GET or POST data. Each time when web
browser sends request back, then session_id value can be used to keep the track of
different web browsers.
This could be an effective way of keeping track of the session but clicking on a
regular (<A HREF...>) hypertext link does not result in a form submission
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
56. Lecture No. 8
JSP Session Tracking
URL Rewriting
You can append some extra data on the end of each URL that identifies the
session, and the server can associate that session identifier with data it has stored
about that session.
For example, with http://tutorialspoint.com/file.htm;sessionid=12345, the
session identifier is attached as sessionid=12345 which can be accessed at the web
server to identify the client
URL rewriting is a better way to maintain sessions and works for the browsers
when they don't support cookies but here drawback is that you would have
generate every URL dynamically to assign a session ID though page is simple
static HTML page
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
57. Lecture No. 8
JSP Session Tracking
The Http Session API
JSP makes use of servlet provided HttpSession Interface which provides a way
to identify a user across more than one page request or visit to a Web site and to
store information about that user.
By default, JSPs have session tracking enabled and a new HttpSession object is
instantiated for each new client automatically
The JSP engine exposes the HttpSession object to the JSP author through the
implicitsession object
Since session object is already provided to the JSP programmer, the
programmer can immediately begin storing and retrieving data from the object
without any initialization or getSession().
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
58. Lecture No. 9
JSP Error Handling and Debugging
When you are writing JSP code, a programmer may leave a coding errors
which can occur at any part of the code. You can have following type of errors
in your JSP code:
Checked exceptions: A checked exception is an exception that is typically a user
error or a problem that cannot be foreseen by the programmer. For example, if a file is
to be opened, but the file cannot be found, an exception occurs. These exceptions
cannot simply be ignored at the time of compilation.
Runtime exceptions: A runtime exception is an exception that occurs that probably
could have been avoided by the programmer. As opposed to checked exceptions,
runtime exceptions are ignored at the time of compilation.
Errors: These are not exceptions at all, but problems that arise beyond the control of
the user or the programmer. Errors are typically ignored in your code because you can
rarely do anything about an error. For example, if a stack overflow occurs, an error will
arise. They are also ignored at the time of compilation.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
59. Lecture No. 9
JSP Error Handling and Debugging
JSP gives you an option to specify Error Page for each JSP. Whenever the page
throws an exception, the JSP container automatically invokes the error page.
Example
<%@ page errorPage="ShowError.jsp" %>
<html> <head> <title>Error Handling Example</title> </head>
<body>
<% // Throw an exception to invoke the error page
int x = 1;
if (x == 1)
{
throw new RuntimeException("Error condition!!!");
}
%>
</body> </html>
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
Showerror.jsp
<%@ page isErrorPage="true" %>
<html> <head> <title>Show Error Page</title> </head>
<body> <h1>Opps...</h1>
<p>Sorry, an error occurred.</p> <p>Here is the exception stack trace: </p>
<pre>
<% exception.printStackTrace(response.getWriter()); %>
</pre>
</body>
</html>
60. Lecture No. 9
JSP Error Handling and Debugging
Using Try-catch Block
<html>
<body>
<%
try
{ int i=1, j=0;
i=i/j;
out.print(“Answer is:”+ i);
}
catch(Exception e)
{
out.println(e.getMessage());
} %> </body></html>
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
61. Lecture No. 9
JSP Debugging
It is always difficult to testing/debugging a JSP and servlets. JSP and Servlets
tend to involve a large amount of client/server interaction, making errors likely
but hard to reproduce.
You can use the following techniques to debug a JSP application:
Using System.out.println()
System.out.println() is easy to use as a marker to test whether a certain piece of
code is being executed or not. Additionally:
Since the System object is part of the core Java objects, it can be used
everywhere without the need to install any extra classes. This includes Servlets,
JSP, RMI, EJB's, ordinary Beans and classes, and standalone applications.
Compared to stopping at breakpoints, writing to System.out doesn't interfere
much with the normal execution flow of the application, which makes it very
valuable when timing is crucial
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
62. Lecture No. 9
JSP Debugging
Using the JDB Logger
The J2SE logging framework is designed to provide logging services for any
class running in the JVM. So we can make use of this framework to log any
information.
Debugging Tools
NetBeans
It is a free and open-source Java Integrated Development Environment that
supports the development of standalone Java applications and Web
applications supporting the JSP and servlet specifications and includes a JSP
debugger as well.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
63. Lecture No. 9
JSP Debugging
NetBeans supports the following basic debugging functionalities:
Breakpoints
Stepping through code
Watchpoints
JDB Debugger
You can debug JSP and servlets with the same jdb commands you use to debug an
applet or an application.
To debug a JSP or servlet, you can debug sun.servlet.http.HttpServer, then watch as
HttpServer executing JSP/servlets in response to HTTP requests we make from a
browser.
This is very similar to how applets are debugged. The difference is that with applets,
the actual program being debugged is sun.applet.AppletViewer
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
64. Lecture No. 9
JSP Debugging
To automatically knowing how to debug your application, you have to help your
debugger by doing the following:
Set your debugger's classpath so that it can find sun.servlet.http.Http-Server
and associated classes
Set your debugger's classpath so that it can also find your JSP and support
classes, typically ROOTWEB-INFclasses.
Once you have set the proper classpath, start debugging
sun.servlet.http.HttpServer. You can set breakpoints in whatever JSP you're
interested in debugging, then use a web browser to make a request to the
HttpServer for the given JSP (http://localhost:8080/JSPToDebug)
Using Comments
The JSP uses Java comments and single line (// ...) and multiple line (/* ... */)
comments can be used to temporarily remove parts of your Java code
If the bug disappears, take a closer look at the code you just commented and
find out the problem
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
65. Lecture No. 9
JSP Debugging
Client and Server Headers
Sometimes when a JSP doesn't behave as expected, it's useful to look at the raw
HTTP request and response.
If you're familiar with the structure of HTTP, you can read the request and
response and see exactly what exactly is going with those headers.
Important Debugging Tips
Ask a browser to show the raw content of the page it is displaying. This can
help identify formatting problems. It's usually an option under the View menu
Make sure the browser isn't caching a previous request's output by forcing a
full reload of the page. With Netscape Navigator, use Shift-Reload; with
Internet Explorer use Shift-Refresh.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
66. Lecture No. 10
COM/DCOM
COM
COM, an acronym for the Component Object Model is a software
architecture that defines a set of standards for component interoperability.
COM is a specification for writing applications that can used by other
applications.
It has the following features that put it on the top of the software world:
Platform Independence
It runs on all the windows platform, as well as many flavors of Unix and
Macintosh.
Implementation Independence
COM servers and clients can be created in any development environment, from
simple Notepad text files to Visual Basic, Visual J++ or Visual C++.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
67. Lecture No. 10
COM/DCOM
Location Independence
COM server and clients need not be on the same computer, with DCOM
(Distributed COM) a server can be on a different machine from its client.
A COM object generally has following characteristics:
A COM object may contain data.
It may have one or more set of functions called interface that provide
functionality to it.
Interfaces are the only medium by which you can access the data in the
object.
Every COM object is identified by a Globally Unique Identifier (GUID),
which is an identifier that uniquely identifies an object across time and space.
Every COM object must implement at least one interface called Iunknown.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
69. Lecture No. 10
COM/DCOM
DCOM
DCOM extends COM to support communication among objects on different
computers- on a LAN, a WAN or even Internet.
DCOM is Internet-savey aside from the setup on the client and server, the
inter-object calls are transparent to the client and even to programmer.
COM in distributed environment work on an inter-process mechanism
called Remote Procedure Calls (RPC).
Need for writing Distributed Applications:
Distributed Applications can accommodate different clients with different
capabilities by running components on the client side when possible and running
them on server side when necessary.
Designing distributed applications gives the system manager a great deal of
flexibility in deployment.
Distributed applications are more scalable i.e., addition or removal of
components is easier.
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut
70. Lecture No. 10
COM/DCOM
DCOM consist of four aspects:
Remote Installation makes DCOM possible.
DCOM take care of Network transport issues.
Marshalling allows location transparency in DCOM.
Security ties DCOM clients and servers together safely.
Advantages of DCOM
Reusability of Components
Location independence
Language neutrality
Connection management
Web Technology (ECS-604) @ Vidya College of Engineering, Meerut