Sunday, January 20, 2008

Installing ASP.NET

ASP.NET is easy to install. Just follow the instructions below.


What You Need

A Windows Computer

ASP.NET is a Microsoft technology. To run ASP.NET you need a computer capable of running Windows.

Windows 2000 or XP

If you are serious about developing ASP.NET applications you should install Windows 2000 Professional or Windows XP Professional.

In both cases, make sure you install the Internet Information Services (IIS) from the Add/Remove Windows components dialog.

Service Packs and Updates

Before ASP.NET can be installed on your computer, it is necessary to have all relevant service packs and security updates installed.

The easiest way to do this is to activate your Windows Internet Update. When you access the Windows Update page, you will be instructed to install the latest service packs and all critical security updates. For Windows 2000, make sure you install Service Pack 2. I will also recommend that you install Internet Explorer 6.

Read the note about connection speed and download time at the bottom of this page.


Remove Your Beta Version

If you have a Beta version of ASP.NET installed, we recommend that you completely uninstall it. Or even better: start with a fresh Windows 2000 or XP installation.


Install .NET

From your Windows Update you can now select to install the Microsoft .NET Framework.

After download, the .NET framework will install itself on your computer - there are no options to select for installation.

You should now be ready to develop your first ASP.NET application!


The .NET Software Development Kit

If you have the necessary bandwidth to download over 130 MB, you might consider downloading the full Microsoft .NET Software Development Kit (SDK).

We fully recommend getting the SDK for learning more about .NET and for the documentation, samples, and tools included.


Connection Speed and Download Time

If you have a slow Internet connection, you might have problems downloading large files like the service packs, the SDK and the latest version of Internet Explorer.

If download speed is a problem, our best suggestion is to get the latest files from someone else, from a colleague, from a friend, or from one of the CDs that comes with many popular computer magazines. Look for Windows 2000 Service Pack 2, Internet Explorer 6, and the Microsoft .NET Framework.

Read More......

Differences between ASP and ASP.NET

ASP.NET has better language support, a large set of new controls and XML based components, and better user authentication.

ASP.NET provides increased performance by running compiled code.

ASP.NET code is not fully backward compatible with ASP.


New in ASP.NET

  • Better language support
  • Programmable controls
  • Event-driven programming
  • XML-based components
  • User authentication, with accounts and roles
  • Higher scalability
  • Increased performance - Compiled code
  • Easier configuration and deployment
  • Not fully ASP compatible

Language Support

ASP.NET uses the new ADO.NET.

ASP.NET supports full Visual Basic, not VBScript.

ASP.NET supports C# (C sharp) and C++.

ASP.NET supports JScript as before.


ASP.NET Controls

ASP.NET contains a large set of HTML controls. Almost all HTML elements on a page can be defined as ASP.NET control objects that can be controlled by scripts.

ASP.NET also contains a new set of object oriented input controls, like programmable list boxes and validation controls.

A new data grid control supports sorting, data paging, and everything you expect from a dataset control.


Event Aware Controls

All ASP.NET objects on a Web page can expose events that can be processed by ASP.NET code.

Load, Click and Change events handled by code makes coding much simpler and much better organized.


ASP.NET Components

ASP.NET components are heavily based on XML. Like the new AD Rotator, that uses XML to store advertisement information and configuration.


User Authentication

ASP.NET supports forms-based user authentication, including cookie management and automatic redirecting of unauthorized logins.

(You can still do your custom login page and custom user checking).


User Accounts and Roles

AS .NET allows for user accounts and roles, to give each user (with a given role) access to different server code and executables.


High Scalability

Much has been done with ASP.NET to provide greater scalability.

Server to server communication has been greatly enhanced, making it possible to scale an application over several servers. One example of this is the ability to run XML parsers, XSL transformations and even resource hungry session objects on other servers.


Compiled Code

The first request for an ASP.NET page on the server will compile the ASP.NET code and keep a cached copy in memory. The result of this is greatly increased performance.


Easy Configuration

Configuration of ASP.NET is done with plain text files.

Configuration files can be uploaded or changed while the application is running. No need to restart the server. No more metabase or registry puzzle.


Easy Deployment

No more server restart to deploy or replace compiled code. ASP.NET simply redirects all new requests to the new code.


Compatibility

ASP.NET is not fully compatible with earlier versions of ASP, so most of the old ASP code will need some changes to run under ASP.NET.

To overcome this problem, ASP.NET uses a new file extension ".aspx". This will make ASP.NET applications able to run side by side with standard ASP applications on the same server.

Read More......

Perl vs PHP

Perl vs PHP

PHP is another computer language. In a way, Perl and PHP are competitors in the programming world. Both languages have relatively similar learning curves, work well in the server environment, and have similar overall capabilities.

As you would expect, each language has its pros and cons. Ideally the webmaster would be able to use either language and choose the best one for a given project. However most programmers have a preference for one over the other and will tend to use their favourite.

In recent years PHP has become more popular with new programmers, in particular, web designers learning their first programming language. This may be because PHP is slightly easier to learn from a web design point of view. PHP pages are constructed like HTML pages, with standard HTML markup. PHP code is inserted into the page and executed when the page is requested. Conversely, Perl scripts are run as stand-alone programs and create HTML pages when the script is run.

Another issue is speed and efficiency. PHP is generally considered to be faster than Perl, although this is debatable. In any case there are certainly ways to make Perl perform as fast. PHP supporters often cite speed as a good reason to choose PHP, but in reality it is not normally a concern and any differences are usually academic.

Perl is a very powerful, robust language with more history than PHP. Although the newbie might think that Perl is more complicated than it needs to be for web development, experienced programmers will appreciate the vast array of options available with Perl.

In our opinion....

In regard to web development, we have yet to find a single thing that Perl can't do, whereas we have found limitations in PHP. We feel that the added power of Perl makes it the better choice. We have not found the efficiency issue to be much of an issue at all - in most cases it's only academic and won't actually affect the performance of your website.

In the end, either language will be adequate for most web development requirements.

Read More......

ASP vs. PHP - Which one is right for you

ASP vs. PHP - Which one is right for you

Too many acronyms!
With all of the acronyms floating around the Web genre, it's difficult to keep track of the new (or old for that matter) technologies. But there are two acronyms that stand out in today's Web design vernacular more so than any others do. ASP and PHP are different approaches to building dynamic Web sites that can incorporate database interactivity and other application server uses into your Web site.

ASP stands for Active Server Pages and PHP formerly stood for Personal Home Pages and is now known as PHP Hypertext Preprocessor.

The breakdown!
ASP is a toy from the Microsoft development toy chest and is used with "Internet Information Server" (IIS) which is a program that runs on Microsoft servers. ASP is generally not supported beyond Microsoft servers. However, there are 3rd party applications that can make it compatible with a few other servers. ASP is widely used for large companies Web needs.

Rasmus Lerdorf originally designed the PHP parsing language during 1994/1995. Some other major contributors were Zeev Suraski and Andi Gutmans who rewrote the parsing engine to create PHP version 3. The major NT and UNIX Web servers support it and it is widely used with the mySQL database. Small and medium Web developers use it religiously.

Do you need either one?
The need for either of these Web development tools is derived from the inability to control the end-users computer. In other words Web developers don't have control over what applications their site traffic may or may not have on their user system. Does a client have Access Database or SQL? Does the client have Microsoft Word or Corel Word Perfect? If your site is going to incorporate "on-the-fly" Web page design that will include database, word-processing and other application data, a developer has to know exactly what apps will be used to generate Web content. The best way to control this is to have all content generated on the Server instead of the client.

Sever Side Scripting is the way today's Web pages are run. Static Web sites (no dynamics) that just have information and no interactivity with server programs are becoming less of the norm. It is no longer a huge financial burden to pull off dynamic content. There are many free servers that allow you to write scripts to the server and you can run a full throttle business class site with just a small financial contribution each month using some of the more sophisticated Web hosting packages offered by today's Web space hosts. The real question is, which dynamic program do you want to use.

The learning Curve! ASP
http://msdn.microsoft.com/

ASP is not a straightforward program that can be picked up from scratch easily. However this is typical of a Microsoft application. The major reasons that large companies are running it instead of PHP include the following 3 important factors.

  • Microsoft products are all over the globe and it makes their site compatible with a significant number of other big businesses sites. This makes business to business transactions easier because everyone involved is running the same platforms and applications.
  • Large companies already have their computers running Microsoft products and their employees are trained in the Microsoft program environment. This keeps training investments down to a minimum and keeps companies from investing in new equipment and software. They get to milk their current Microsoft product assets for all that they are worth.
  • If a large company wants to take over another (an acquisition or merger) or is bought out themselves, the ability to easily integrate systems (databases, document processing, spread sheet and accounting applications) is invaluable and can make a company appear to be a much more attractive prospect to potential benefactors. Therefore keeping your business dressed up in MS clothing can have a certain appeal.

There are many small and medium business that choose to run ASP as well. Most of these already were using NT, Excel and Access. Using IIS (Internet Information Server) to access their spreadsheet, database and word-processor applications to incorporate data into Web content is an easy transition.

Trying to incorporate existing Microsoft application data into a PHP run Web site would require starting from scratch with a great deal of headaches including purchasing new programs. Therefore some small and medium sized businesses that already are hooked on Microsoft products may opt for ASP as well.

However PHP is the developers tool that has gained the most respect amongst Web gurus and aficionados. Most describe it as an easy to use and feature packed program that allows you to create dynamic and database driven Web sites effortlessly. It is a free program that is open source so it can be modified to fit developers needs. Most developers who like Linux and mySQL are also fans of PHP.

The learning Curve! PHP
http://www.php.net/

Independent Web developers as well as a growing number of small and medium sized businesses love PHP. They have jumped onboard the PHP bandwagon and love every trail they blaze. What are the secrets behind the rapid growth of PHP and what are the advantages to using this highly regarded program?

  • It's easy to learn and the available support for it is through the roof. The Web has always been about individuals banding together to create resources for one another. PHP is loved by the Web community and you will find and abundance of tutorials, tools, Web sites and other online support ready and available to guide you from your Web sites conception to it's launch.
  • More and more host servers are supporting PHP; chances are you can find a good free or cheap host for your site that will allow you to run a dynamic PHP site.
  • ASP is supported by Microsoft servers only (unless you use a 3rd party utility that facilitates support); however, PHP is supported by many different "html" servers.

What else separates the two?
PHP has it's own language and syntax, the language is simplified due to the programs incorporation of a parsing engine that is especially designed to make short work of translating PHP code into machine language that executes commands.

ASP makes use of a language that was dying before Microsoft managed to breathe new life into it. Visual Basic Script is the language used in ASP and was formerly used (and still is used by some developers) as a client side scripting language that was in direct competitions with JavaScript. This was back when Internet Explorer was still the #2 browser behind Netscape Navigator. During this era, JavaScript was whooping the pants of Visual Basic Script with its wide acceptance amongst Web developers.

However client side scripting languages were an invention of necessity and thrived in an era when Web hosting was an expensive operation and paying for server script access usually meant writing in CGI (Common Gateway Interface) languages like Perl that were difficult to learn. But these obstacles no longer exist. Today it's far too cheap and too easy to use ASP or PHP to create a dynamic site. There's no reason to be limited to only client side scripting.

Nevertheless, Microsoft was able to keep yet another product afloat by ingeniously (cough...cough) using it as the language catalyst for getting the IIS to generate dynamic web pages.

Are there any other alternatives?

JSP
http://java.sun.com/products/jsp/docs.html

(Java Server Page) is an extension to the Java servlet technology pioneered by Sun. Like ASP and PHP it provides a simple programming vehicle for displaying dynamic Web content. JSP is the Sun/Java attempt to compete with Microsoft's ASP. JSP is not widely used however it has a small core of enthusiasts who are claiming it to be as powerful and dynamic as ASP. These patrons usually fail to even acknowledge the PHP genres existence (probably because PHP is far more popular than JSP).

ColdFusion:
http://www.allaire.com/products/ColdFusion/whyuse.cfm

ColdFusion is an application development tool created by Allaire Corporation. It is used for writing Web pages that interact with databases. ColdFusion Markup Language (CFML) makes use of HTML-like tags that are embedded in the Web pages. ColdFusion uses an engine (like PHP), which interfaces with a Windows-based Web server (obviously an attempt to make good use of the huge client base afforded to Microsoft). However this would explain the reason it's not as popular as PHP amongst the anti Microsoft genre.

The verdict!
Which one you choose is based on many variables but none more important than preference. When people visit your site they won't say, "Man, this page was generated by ASP; that sucks!" What they will do is evaluate the site's usefulness based on design and content. Therefore as long as your site follows the rules of good design and also provides the content that the client was looking for any of these dynamic content tools will work just fine, so take your pick.

Read More......

JSP vs ASP

JSP vs ASP

Introduction

5-6 years back it was easy to choose a server-side language as CGI used to be only the only scripting language available. But in due course of time, the developers found out that CGI scripts were inefficient and it was very difficult to write server extensions.

At that time, Microsoft came up with Active Server Pages (ASP), which allows developers to use simple scripting to access the server and its extensions. But ASP had some disadvantages. It limits you to work on Microsoft platforms, and the simplest of mistakes in the script can cause the server to crash or hang, effectively bringing down your website.

In response to ASP, Sun Microsystems gave the world Java Server Pages (JSP) technology, which is entirely based on Java programming language. Internally, JSP pages are dynamically converted into Servlets, which are simply Java classes. This means JSP enjoys all the capabilities that Java programming supports.

JSP is a great deal more efficient than many other scripting languages, such as CGI and ASP. Tags can be defined in tag libraries and then used within any JSP page. This makes for a better separation of page content from its code, which leads to less scattered code and hence, the site is easier to maintain. Global changes need to be made only to the tags defined in these tag libraries, making time-consuming, page-by-page fixes things of the past.

JSP versus ASP

JSP and ASP have some basic concepts in common.

1) They both make use of simple sever-side scripting to provide access to Web server information and functionality.

2) They both have similar styles of delimiting this scripting from a page's content. In fact, Microsoft's has recently come up with ASP+ is much more similar to JSP than ASP.

Yet while ASP primarily supports two scripting languages, JScript and VBScript, JSP actually supports real Java code, not a new scripting language. The difference is that the Java code inside a JSP page is more script-like because it doesn't require Java class and package definitions. JScript, VBScript, and Java
(in JSP) are all object oriented to some degree as they are all
provided with a set of pre-established objects by the Web server
that they use to generate a dynamic Web page.

The following table lists some of the instantiated objects that are available in both ASP and JSP.

JSP ASP Definition
Request Request Access to request information.
Response Response Access to response information.
Session Session Access to session information.
Application Application Access to application information.
Out Response.Write Access to the response output stream

Note that JSP is case sensitive. But VBScript is not.

As I mentioned earlier, both ASP and JSP support a similar way of delimiting scripting from content on a page. <% and %> are used to set of sections of script, '<%=' and '%>' are used to return a value within content, and <%@ and %> are used to delimit page directives.

JSP supports two basic styles of delimiting its scripting elements from page content. The first looks a great deal like ASP, whereas the second can be used to create JSP that is fully XML compliant. Here, let's examine these styles:

Base Style XML Style Description
<%@ directive %> Directives are used to specify page information, include other files, and specify tag libraries being used.
<%! declarative code %>
declarative code

You can declare new methods using these tags.
<% code fragment %>
code fragment

This code is placed within a base method of the generated servlet.
<%= code expression %>
code expression

This code is appended to the output stream being returned for the page.

Conclusion

In many ways, the biggest difference between JSP and ASP technologies lies in the approach to the software design itself. JSP technology is designed to be both platform and server independent, created with input from a broader community of tool, server, and database vendors. In contrast, ASP is a Microsoft technology that relies primarily on Microsoft technologies.

Now as we have seen the advantages of JSP over ASP, I'll like to share some information on JSP with you:

" There are a number of servers that support JSP on the market. The popular ones are Tomcat, Jrun and Enhydra.

" Another powerful feature of JSP that we haven't covered in this article is its ability to utilize JavaBeans with special tags defined in JSP. For more information about this, you can refer to Sun's JavaBean overview.

If you want to learn JSP, the best place to start is at the Sun Microsystems web site (http://java.sun.com). Their support pages include the JSP specification and documentation of the supporting Java classes. As you explore, make sure you get a good idea about the underlying Java Servlet technology, since this is what all JSP must become behind the scenes.

As you open up JSP and really see what it can do, you'll soon find that, with practice, anyone (not just Java developers) can make use of the powerful set of tools that JSP provides.

Read More......

JavaServer Pages[tm] Technology - Comparison with ASP

JavaServer Pages[tm] Technology - Comparison with ASP








Introduction

At first glance, JavaServer PagesTM (JSP) and Microsoft Active Server Pages (ASP) technologies have many similarities. Both are designed to create interactive pages as part of a Web-based application. To a degree, both enable developers to separate programming logic from page design through the use of components that are called from the page itself. And both provide an alternative to creating CGI scripts that makes page development and deployment easier and faster.

While JavaServer Pages technology and Microsoft Active Server Pages are similar in many ways, there are also a number of differences that exist. And these differences are just as significant as the similarities, and have far-reaching implications for the developers who use them as well as the organizations that adopt them as part of their overall Web-based architecture.

JSP Technology: An Open Approach

In many ways, the biggest difference between JSP and ASP technologies lies in the approach to the software design itself. JSP technology is designed to be both platform and server independent, created with input from a broader community of tool, server, and database vendors. In contrast, ASP is a Microsoft technology that relies primarily on Microsoft technologies.

Platform and Server Independence

JSP technology adheres to the Write Once, Run AnywhereTM philosophy of the JavaTM architecture. Instead of being tied to a single platform or vendor, JSP technology can run on any Web server and is supported by a wide variety of tools from multiple vendors.

Because it uses ActiveX controls for its components, ASP technology is basically restricted to Microsoft Windows-based platforms. Offered primarily as a feature of Microsoft IIS, ASP technology does not work easily on a broader range of Web servers because ActiveX objects are platform specific.

Although ASP technology is available on other platforms through third-party porting products, to access components and interact with other services, the ActiveX objects must be present on the selected platform. If not present, a bridge to a platform supporting them is required.

Open Development Process, Open Source

Sun developed JSP technology using the Java Community Process. Since 1995, Sun has used this open process to develop and revise Java technology and specifications in cooperation with the international Java community. Working with Sun in the JSP effort are authoring tool vendors (such as Macromedia), container companies (such as Apache and Netscape), end users, consultants, and others. Going forward, Sun is licensing the latest versions of JSP and JavaTM Servlet (JSP 1.1 and Java Servlet 2.2) source code to Apache to be developed and released under the Apache development process. Apache, Sun, and a number of other companies and individuals will openly develop a robust reference implementation (RI) that is freely available to any company or individual. Additional information can be found at http://jakarta.apache.org/.

The JSP application programming interface (API) has undoubtedly benefited - and will continue to benefit - from the input of this extended community. In contrast, ASP technology is a specifically Microsoft initiative, developed in a proprietary process.





ASP Technology
JSP Technology
Web Server
Microsoft IIS or Personal Web Server
Any Web server, including Apache, Netscape, and IIS
Platforms
Microsoft Windows1
Most popular platforms, including the Solaris Operating Environment, Microsoft Windows, Mac OS, Linux, and other UNIX platform implementations
1. Accessing other platforms requires third-party ASP porting products.


For a company selecting the components of a growing, Web-based information architecture, JSP technology provides a flexible, open choice that works with a wide variety of vendors' tools and reflects industry input and collaboration.

The Developer's Perspective

Both ASP and JSP technologies let developers separate content generation from layout by accessing components from the page. ASP supports the COM model, while JSP technology provides components based on JavaBeansTM technology or JSP tags.

As noted previously, the differences outweigh the similarities.

Extensible JSP Tags

The first difference apparent to any page author are the JSP tags themselves. While both ASP and JSP use a combination of tags and scripting to create dynamic Web pages, JSP technology enables developers to extend the JSP tags available. JSP developers can create custom tag libraries, so page authors can access more functionality using XML-like tags and depend less on scripting. With custom tags, developers can shield page authors from the complexities of page creation logic and extend key functions to a broader range of authors.

Reusability Across Platforms

Developers will also notice the focus on reusability. The JSP components (Enterprise JavaBeansTM, JavaBeans, or custom JSP tags) are reusable across platforms. An Enterprise JavaBean component accessing legacy databases can serve distributed systems on both UNIX and Microsoft Windows platforms. And the tag extension capability of JSP technology gives developers an easy, XML-like interface for sharing packaged functionality with page designers throughout the enterprise.

This component-based model speeds application development because it enables developers to:

  • Build quick prototype applications using lightweight subcomponents, then integrate additional functionality as it becomes available

  • Leverage work done elsewhere in the organization and encapsulate it in a JavaBean or Enterprise JavaBean component

The Java Advantage

JSP technology uses the Java language for scripting, while ASP pages use Microsoft VBScript or JScript. The Java language is a mature, powerful, and scalable programming language that provides many benefits over the Basic-based scripting languages. For example, the Java language provides superior performance to the interpreted VBScript or JScript languages. Because they use Java technology and are compiled into Java servlets, JSP pages provide a gateway to the entire suite of server-side Java libraries for HTTP-aware applications.

The Java language makes the developer's job easier in other ways as well. For example, it helps protect against system crashes, while ASP applications on Windows NT systems are susceptible to crashing. The Java language also helps in the area of memory management by providing protection against memory leaks and hard-to-find pointer bugs that can slow application deployment. Plus, JSP provides the robust exception handling necessary for real-world applications.

Easier Maintenance

Applications using JSP technology are easier to maintain over time than ASP-based applications.

  • Scripting languages are fine for small applications, but do not scale well to manage large, complex applications. Because the Java language is structured, it is easier to build and maintain large, modular applications with it.

  • JSP technology's emphasis on components over scripting makes it easier to revise content without affecting logic, or revise logic without changing content.

  • The Enterprise JavaBeans architecture encapsulates the enterprise logic, such as database access, security, and transaction integrity, and isolates it from the application itself.

  • Because JSP technology is an open, cross-platform architecture, Web servers, platforms, and other components can be easily upgraded or switched without affecting JSP-based applications. This makes JSP suitable for real-world Web applications, where constant change and growth is the norm.





ASP Technology
JSP Technology
Reusable, Cross-Platform Components
No
JavaBeans, Enterprise JavaBeans, custom JSP tags
Security Against System Crashes
No
Yes
Memory Leak Protection
No
Yes
Scripting Language
VBScript, JScript
Java
Customizable Tags
No
Yes


Scalability in the Enterprise

The Java 2 Platform, Enterprise Edition (J2EE) is the Java architecture for developing multitier enterprise applications. As part of J2EE, JSP pages have access to all J2EE components, including JavaBeans and Enterprise JavaBeans components and Java servlets. JSP pages are actually compiled into servlets, so they have all of the benefits of these flexible, server-side Java applications. The J2EE platform containers manage the complexities of enterprise applications, including transaction management and resource pooling.

JSP pages have access to all of the standard J2EE services, including:

Through J2EE, JSP pages can interact with enterprise systems in many ways. J2EE supports two CORBA-compliant technologies: Java IDL and RMI-IIOP. With Enterprise JavaBeans technology, JSP pages can access databases using high-level, object-relational mappings.

Finally, because JSP technology was developed through the Java Community Process, it has wide support from tool, Web server and application server vendors. This enables users and partners take a best-of-breed approach, selecting the best tools for their specific applications while protecting their investment in code and in personnel training.





ASP Technology
JSP Technology
Compatible with Legacy Databases
Yes (COM)
Yes (using JDBC API)
Ability to Integrate with Data Sources
Works with any ODBC-compliant database
Works with any ODBC- and JDBC technology-compliant database
Components
COM components
JavaBeans, Enterprise JavaBeans, or extensible JSP tags
Extensive Tool Support
Yes
Yes

Read More......

How JSP compares with ASP





Introduction to JSP



Choosing a server-side language used to be easy. Way back when, CGI was pretty much the only scripting option out there. Intrepid developers could write their own server extensions, but few were up to the challenge, and the gap between these two options (inefficient CGI scripts and extremely complex server extension development) was huge.



Microsoft tried to fill this hole with Active Server Pages (ASP), which allow developers to use simple scripting to access the server and its extensions. But while ASP gives you an efficient way to return dynamic content, it essentially limits you to Microsoft platforms, and even the simplest of scripting mistakes can cause the server to crash or hang, effectively bringing down your website.



Apparently in response to ASP, Sun Microsystems gave the world JavaServer Pages (JSP) technology, which is based entirely upon Sun's popular Java programming language and gives developers the advantages of developing in Java in a more relaxed, script-like environment. Behind the scenes, JSP pages are dynamically assembled into Servlets, which are simply Java classes. This means JSP supports the same modularity, reusability, platform-independence, and access to Java APIs that Java programming supports.



Thanks to its foundation in Java and its use of Java threads to handle incoming requests, JSP is a great deal more efficient than many other scripting languages, such as CGI. Its threading model and error handling also help prevent server hangs and crashes. And when the underlying Java Virtual Machine (JVM) makes use of Just In Time (JIT) compilation, the performance of well-written JSP can approach that of C++.



JSP also bests ASP by supporting the definition of tags that abstract functionality within a page, so tags can be defined in a tag library and then used within any JSP page. This makes for a better separation of page content from its code, which is one of Web development's prime directives. The less code scattered throughout the pages of a website, the easier the site is to maintain. Global changes need only be made to the tags defined in a central library, making time-consuming, page-by-page fixes things of the past.



For XML lovers, good news: JSP pages can be written in well-formed, valid XML by using XSLT. (For those of you who aren't XML-spawn, this simply means that JSP can make full use of a very powerful and widely accepted data format and all the tools and support that go with it.)



And unlike ASP, JSP is a lot less platform-specific and it doesn't rely as heavily on the company that created it for support or performance improvements. That said, there are some similarities between JSP and ASP. Here, let's closer look at how the two compare.







JSP versus ASP





JSP and ASP do have some basic concepts in common. They both make use of simple sever-side scripting to provide access to Web server information and functionality. They both do so using object oriented scripting. And they both started out with similar styles of delimiting this scripting from a page's content. In fact, Microsoft is replacing ASP with ASP+, which is even more like JSP than ASP in that its pages are compiled upon request and run in a 'virtual machine' (which supports multiple languages and is written in C#).




Yet while ASP primarily supports two scripting languages -- JScript and VBScript -- JSP actually supports real Java code, not a new scripting language. The difference is that the Java code inside a JSP page is more script-like because it doesn't require Java class and package definitions. As you will see, the Java code inside JSP is added to methods of a Java Servlet that are generated the first time the JSP is requested. Of course, JScript, VBScript, and Java are all object oriented to some degree, or maybe to avoid getting into a political argument with those of you would dispute this claim I should refer to them as 'Quasi-Object-Oriented.' Whatever we choose to call them, we can at least agree that the scripting languages used by JSP and ASP are all provided with a set of pre-established objects by the Web server that they use to generate a dynamic Web page.



The following table lists some of the pre-established (instantiated, for the purist) objects that are available in both ASP and JSP.












































ASP JSP Definition
Request request Access to request information. This includes such items as input/form parameters, HTTP request header information, etc.
Response response Access to response information and construction. This includes output MIME type and other HTTP
response headers as well as the output stream itself.
Session session Access to session information.
Application application Access to application information.
Response.Write out Access to the response output stream. JSP provides a convenience object for direct output to this stream, whereas ASP uses a Response object method.


Note that JSP is Java, so it is case sensitive. But capitalization doesn't matter in VBScript, so if you stick to lowercase, there really isn't any difference in the names.



These are the main objects we have to work with when creating dynamic content in either ASP or JSP, so it's a good idea to become familiar with their methods. I'll use some of them in the examples that follow, but I can't go into every method available within the limits of this article.



As I mentioned earlier, both ASP and JSP support a similar way of delimiting scripting from content on a page. <% and %> are used to set of sections of script, '<%=' and '%>' are used to return a value within content, and <%@ and %> are used to delimit page directives. Here is a brief example using both ASP and JSP:










ASP (using JScript)

<%@ LANGUAGE = JScript %>

<TITLE>Simple Scripting Tricks</TITLE>
Anyone can count like this:<BR>
<%
for (i = 1; i < 6; i++) {
Response.Write(i + "<BR>");
}
i = 1000000;
%>
It would take a long time, however, to count to <%= i %>.






JSP


<%@ page language="java" %>
<TITLE>Simple Scripting Tricks</TITLE>
Anyone can count like this:<BR>
<%
for (int i = 1; i < 6; i++) {
out.println(i + "<BR>");
}
i = 1000000;
%>
It would take a long time, however, to count to <%= i %>.








HTML Output (from either JSP or ASP)

<TITLE>Simple Scripting Tricks</TITLE>
Anyone can count like this:<BR>
1<BR>
2<BR>
3<BR>
4<BR>
5<BR>
It would take a long time, however, to count to 1000000.




As you can see, there are some basic similarities between ASP
and JSP. In fact, in this simple example, there's almost no
difference. When we look deeper into JSP, however, fundamental
differences will appear.








JSP Syntax



JSP supports two basic styles of delimiting its scripting elements from page content. The first looks a great deal like ASP, whereas the second can be used to create JSP that is fully XML compliant. Here, let's take a look:






































Base StyleXML Style
Description
<%@ directive %>
<jsp:directive.directive/>
Directives are used to specify page information, include other files, and specify tag libraries being used.
<%! declarative code %>
<jsp:declaration>
declarative code
</jsp:declaration>
This code is placed as a declaration in the servlet that is generated. This is the only
place that new methods can be declared.
<% code fragment %>
<jsp:scriptlet>
code fragment

</jsp:scriptlet>
This code is placed within a base method of the generated servlet.
<%= code expression %>
<jsp:expression>
code expression

</jsp:expression>

Some versions use
<jsp:expr/>


This code is placed within the base method of the generated servlet, where it is appended to the output stream being returned for the page.


To utilize the XML Style delimiters, you have to format your JSP as an XML document. This requires some additional modification, like using <jsp:root/> as your the root XML node and making sure your page is well-formed XML. This conversion and the use of the XML Style are outside the scope of this article, but if XML is important to you or your project, you should definitely investigate them further on your own time.



If you're interested in learning more about XML and JSP, the book Professional Java XML Programming with Servlets and JSP is an excellent investment -- though if you're not quite ready to roll out the dough, JavaSoft's PDF about the matter is free for the downloading.



The most important things to know as you create your JSP website are the four basic types of delimeters: directives, declarations, fragments, and expressions. The following example is a complete JSP page that uses the base style of each delimiter:










LineComplete JSP


1
2
3
4
5
6
7
8
9
10
11
12



<%@ page info="Example"
import="java.io.*,java.util.*" %>

<%! String title = "Example JSP Page" %>
<%@ include file ="header.inc" %>
Anyone can count like this:<BR>
<%
for (int i = 1; i < 6; i++) {
out.println(i + "<BR>");
}
i = 1000000;
%>
It would take a lifetime, however to count to <%= i %>.
<%@ include file ="footer.inc" %>





In line 1, the page directive sets the generated servlet info to 'Example' and makes sure that 'java.io.*' and 'java.util.*' are imported for use in the servlet. The import is, well, important, since without these imports there would be no access to additional Java APIs.



Line 2 declares title as a class variable. This variable can now be used in any following code. Most likely, it is used by the code in header.inc, which is included in place on line 3.



Line 4 is plain page content. This is sent to the output stream.



Lines 5 through 10 define a code fragment that writes out the numbers 1 to 5, with breaks in between, to the output stream.



Line 6 is page content that includes an expression. This content is sent to the output stream with the expression inserted.



Line 7 includes the footer.inc file, which presumably has some more content we want to place at the bottom of this file.



If you followed all that, then you now have a basic understanding of JSP syntax and are armed with enough
knowledge to do some small amount of damage to your website. One gotcha that you should know about is that when included files are changed, the servlet generated by the JSP is not usually regenerated. So if you make a change to an included file, make sure to tell your server to regenerate the servlet for the including JSP. Another way to do this is to re-save the including JSP. This changes the file modification timestamp, which is supposed to cause the servlet to regenerate.



Now that we've taken a look at the basic syntax, let's take a look at how we can use the access objects that JSP provides us to detect the incoming browser and respond appropriately.





JSP Browser Detection




JSP provides us with access objects that we can use to get information from the incoming request and modify the resulting response. This makes it possible for us to do things like identify what type of browser is making the request. We can then set up a different type of request based upon what that browser supports.



The following example determines whether the incoming browser is Internet Explorer, Netscape, or a WML client (like a cell phone). Depending on the browser it finds, it returns an appropriate greeting. Let's take a gander at an example of this at work. (Note: I'm going to use line numbering here because it makes the explanation of the example so much easier, but it isn't part of the code -- it's just there for reference.)















Browser Detection in JSP

<%@ page info="Greetings" errorPage="err.jsp" %> 





This first line simply adds some arbitrary information to the generated servlet and tells the Web server to redirect any Java errors encountered on the page to the err.jsp page. Other things that can be done in this page directive include importing various Java APIs.













<%!
public final static int IE = 0;
public final static int NETSCAPE = 1;
public final static int WML = 2;

public int getBrowser(HttpServletRequest request) {
String accept = request.getHeader("ACCEPT");
if (null != accept && -1 !=
accept.indexOf("wml")) {
return WML;
}
String agent = request.getHeader("USER-AGENT");
if (null != agent && -1 !=
agent.indexOf("MSIE")) {
return IE;
}
return NETSCAPE;
}
%>






This section of code declares three static values that represent the different browser types we are detecting. It also defines the getBrowser() method that accepts the request object and uses it to determine what browser has made the request. It does so by looking at the ACCEPT HTTP request header to see if the browser will accept wml. If it doesn't, it then looks at the USER-AGENT HTTP request header to see if it contains 'MSIE.' If it does, then the browser making the request is IE. Otherwise, we assume it's a Netscape browser.









<%
switch (getBrowser(request)) {
case WML:
response.setContentType("text/vnd.wap.wml");
%>
<?xml version='1.0'?>
<wml>
<card id='index' title='Browser Greeting'>
<p align='center'>Hello, Wireless Fan!</p>
</card>
</wml>

<%
break;
case IE:
%>
<HTML><BODY><H1>Hello, IE
Fan!</H1></BODY></HTML>
<%
break;
default:
%>
<HTML><BODY><H1>Hello, Netscape
Fan!</H1></BODY></HTML>
<%
}
%>





In the last section of code, we used the declared getBrowser() method in a Java switch statement to determine what should be returned to the browser. For IE and Netscape browsers, a simple HTML document is returned. For WML-accepting browsers, the content type of the response is set to text/vnd.wap.wml and a WML document is returned.



In these very meaningful forty-two lines of code, we have a simple page that will serve up a pleasant greeting to three different browsers. If all has gone well, creating this code should have whetted your appetite for more. If you're interested in pushing JSP even further, then read on for a list of additional resources you can use to expand your JSP horizons.





More JSP



So far, I've touched on creating JSP as a well-formed XML document. I also mentioned the concept of creating a tag library for use throughout your website. But as you dive even further into JSP development, you'll find that there is quite a bit more to learn:




  • There are a number of servers that support JSP on the market. The two I am most familiar with are JRun and Tomcat. I've also used Enhydra, which is an open source application server that uses Tomcat's technology internally. Try one and see how you like it.


  • If you're looking at doing a large-scale project in JSP, I strongly recommend that you create your own tag library because it will make supporting your website a whole lot simpler. For more information about tag libraries, check out JSPtags.com or JSP Insider.


  • Another powerful feature of JSP that we haven't covered yet is its ability to utilize JavaBeans with special tags defined in JSP. For more information about this, peruse Sun's JavaBean overview.



If you're looking to push your JSP envelope further, the best place to start is at the source, Sun Microsystems. Their support pages include the JSP specification and documentation of the supporting Java classes. As you explore, make sure you get a good idea about the underlying Java Servlet technology, since this is what all JSP must become behind the scenes.



You'll find that Sun's site also gives you an extra helping of propaganda. As a rule, you should never believe anyone's marketing department, but in this case, Sun's information to be generally accurate. It is true, for instance, that you can re-use JSP on multiple platforms without much trouble. In my experience, the difficulty of moving from one JSP platform to another lies with the Java APIs that are imported by default. On some platforms you must specifically import java.io.* and on others you don't. It doesn't hurt to import anything that doesn't come from java.lang.*, so do it. It will make your life easier in the future.



As you open up JSP and really see what it can do, you'll soon find that, with practice, anyone (not just Java developers) can make use of the powerful set of tools that JSP provides.






Read More......