ASP vs. JSP

advertisement
ASP vs. JSP
The Need For Server Pages
HTML
HTML is the acronym used for Hyper Text Mark-up Language. It was designed to
provide a standard language for formatting information on web pages so that they could
be viewed on any machine regardless of the platform. An example of a very simple
HTML page can be viewed here.
While HTML achieved the task of providing this standard, it remained stateless. This
meant that when the user moved from one page to another, HTML did not remember the
previous page. This functionality was essential for e-commerce applications since the
design of the shopping cart required that the products selected by the online shopper be
remembered as he/she moved from one product page to another and finally checked out.
This need for dynamic content led to the development of scripting languages.
Server-side scripting vs. Client-side scripting
In the current networking model a server is the machine where the information resides
and a client is the machine requesting that information. In the quest for dynamic content
several scripting languages were developed. Some designed to run on the client side and
others were designed to run on the server side. Since I am not comparing the two in this
paper it should suffice to know that the objective for developing the two types of
languages was to distribute the resource utilization between the client and the server. As
far as functionality is concerned both types provided ways to make web pages not only
dynamic but also gave the key objective of incorporating database connectivity to these
web pages.
Server Pages
Pages that use server-side scripting are called server pages. These pages are dynamic and
complement HTML pages by presenting dynamic content in a presentable format to the
client. Two examples of server-side scripting languages are ASP (Active Server Pages)
and JSP (Java Server Pages). There are several similarities and several differences
between the two languages and I will discuss those in this paper.
Similarities between ASP and JSP
The similarities between the two languages are very few. Aside from both being serverside scripting languages both require that anybody planning on program in either should
have good programming skills and logical thought. What this means is while you might
get away with designing an HTML page without any programming background, you will
have to be ale to program in some language to be able to use ASP or JSP effectively.
Both provide full database connectivity. What this means is that you can use either to run
the same queries against any database and the result would be the same. This also means
that you can use HTML to format pages written in either language to make the output
look the same. An example of pages written in either language with the output looking
the same can be viewed here. Asp ….. JSP.
Differences between ASP and JSP
ASP uses the functionality of Jscript and VBScript to implement pages. Anything that
you can do in either of these scripting languages you can do in ASP. ASP essentially adds
to the functionality of these two languages. JSP on the other hand uses Java to implement
its pages. It not only borrows the robust structure of the Java language but also its
exception handling which makes life a lot easier for the programmer.
One of the attractions of JSP is that it is a translated language. Once the code is run it is
compiled into servelets that utilize classes. These servelets reside on the server and since
they have already been compiled, each time the page is called all it needs to do is utilize
these servelets to display the page. In contrast an ASP is interpreted each time it is
accessed and therefore not only requires more resources as compared to a JSP but also
takes more time to load as compared to a JSP. Each approach has its pros and cons
depending on what kind of application is being developed and all the points discussed in
a translated vs. interpreted debate would apply here. Therefore anybody who thinks that
JSP should always be the language of choice for any kind of project is seriously limiting
the tools available for him/her to develop a good website.
An achievement for JSP is that it has been able to separate programming logic from page
design. What this means is that a webpage designer need not concern himself/herself with
how the database connection is being made or how the dynamic content is being stored.
He/she is provided with custom tags that are being made by a JSP programmer which
he/she can utilize much the same way as an HTML tag would be used. This way the
program logic is separated from the page design. This also means that the JSP
programmer is able to develop custom tags for the page designer. All this is not possible
in ASP and the code for an ASP is littered with programming code segments within the
HTML code.
ASP is a propriety language i.e. it is Microsoft tied. It runs on Microsoft servers and
requires third party software for running it on any other servers. This makes it a little
expensive to implement. JSP on the other hand is an open standard much like the
language that it is based on. This also makes JSP very portable across different platforms.
Once you have compiled the pages they can be run on any server.
One of the advantages that ASP has over JSP is that it has a shorter learning curve. So, if
you are just starting out and are unable to decide which language to tackle first, my
advice to you is to go for ASP first. From a developer’s point of view ASP is much easier
to learn and program in. Once you are familiar with how a server page works JSP seems a
lot easier. From a client’s point of view JSP is the language of choice since it loads much
faster and is more cost effective.
A Few Words of Caution
I have tried to be very objective in my analysis of how JSP differs from ASP but I have
found that that is very difficult. I am a diehard fan of neither but already I see myself
leaning towards JSP as my language of choice. I fear that my loss of objectivity will
effect how I implement my projects in the future. So I caution you against undertaking a
project with mind already made up as to which language you will use to implement it.
Each project will have its own requirements and those requirements will determine which
way you go. Of course there will be a language that you prefer but don’t let that not let
you implement the optimal solution.
I have not included a comparison of JSP with ASP.NET which is the next generation of
ASP. The reader’s time will be well spent if they research this technology as well as it is
in direct competition with JSP.
Some very interesting links that I came across during my research that I thought might
make good starting points for anyone planning to learn either language are given below.
http://www.w3schools.com
http://www.jsptut.com
Code for this example
Back
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
Back
Code for this example
Back
<html>
<head>
<title>Hello World</title>
</head>
<body>
<%response.write "<h1>Hello World</h1>"%>
</body>
</html>
Back
Code for this example
Back
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>
<% out.println("Hello World"); %>
</h1>
</body>
</html>
Back
Questions
1. What is the main difference between server-side scripting and client-side scripting?
2. What are the advantages of JSP being a translated language?
3. Discuss why having a predetermined approach to a project vis-à-vis the language to use
might not be a good idea.
4. State and explain two similarities between ASP and JSP.
5. State and explain two dissimilarities between ASP and JSP.
6. According to the discussion above HTML is a ____________ language.
7. JSP is a/an _____________ standard.
8. _________ has a shorter learning curve as compared to ___________.
9. The need for ___________ content led to the development of scripting languages.
10. Which of the following is the correct format for printing a string to the browser window?
a. <% System.out.println(“Hello World”); %>
b. <% Out.println(“Hello World”); %>
c. <% printBrowserWindow(“Hello World”); %>
d. <% cout(“Hello World”); %>
Download