Chapter 1. Introducing ColdFusion

Understanding ColdFusion

Millions of Web sites exist that attract millions of visitors daily. Many Web sites are being used as electronic replacements for newspapers, magazines, brochures, and bulletin boards. The Web offers ways to enhance these publications using audio, images, animation, multimedia, and even virtual reality.

These sites add value to the Net because information is knowledge, and knowledge is power. All this information is literally at your fingertips. But because of the underlying technology that makes the Web tick, sites can be much more than electronic versions of paper publications. Users can interact with you and your company, collect and process mission-critical information in real time (allowing you to provide new levels of user support), and much more.

The Web isn’t merely the electronic equivalent of a newspaper or magazine—it’s a communication medium limited only by the innovation and creativity of Web site designers.

The Dynamic Page Advantage

Dynamic pages—pages that contain dynamic content—are what bring the Web to life. Linking your Web site to live data is a tremendous advantage, but the benefits of database interaction go beyond extending your site’s capabilities.

To see why dynamic Web pages are becoming the norm, compare them to static pages:

Static Web pages. Static Web pages are made up of text, images, and HTML formatting tags. These pages are manually created and maintained so that when information changes, so must the page. This usually involves loading the page into an editor, making the changes, reformatting text if needed, and then saving the file. And not everyone in the organization can make these changes. The webmaster or Web design team is responsible for maintaining the site and implementing all changes and enhancements. This often means that by the time information finally makes it onto the Web site, it’s out of date.

Dynamic Web pages. Dynamic Web pages contain very little text. Instead, they pull needed information from other applications. Dynamic Web pages communicate with databases to extract employee directory information, spreadsheets to display accounting figures, client-server database management systems to interact with order processing applications, and more. A database already exists. Why re-create it for Web page publication?

Creating dynamic pages lets you create powerful applications that can include features such as these:

• Querying existing database applications for data

• Creating dynamic queries, facilitating more flexible data retrieval

• Generating and working with email, instant messaging, text messaging, and more

• Executing conditional code on the fly to customize responses for specific situations

• Enhancing the standard HTML form capabilities with data validation functions

• Dynamically populating form elements

• Customizing the display of dates, times, and currency values with formatting functions

• Using wizards to ease the creation of data entry and data drill-down applications

• Creating printable content

• Data-driven reports in Adobe PDF formats

• Shopping carts and e-commerce sites

• Data syndication and affiliate programs

Understanding Web Applications

Web sites are powered by Web servers, and Web servers do just that: they serve. Web browsers make requests, and Web servers fulfill those requests—they serve up the requested information to the browser. These are usually HTML files, as well as the other file types discussed previously.

And that’s really all Web servers do. In the grand scheme of things, Web servers are actually pretty simple applications—they sit and wait for requests that they attempt to fulfill as soon as they arrive. Web servers don’t let you interact with a database; they don’t let you personalize Web pages; they don’t let you process the results of a user’s form submission. They do none of that; all they do is serve pages.

So how do you extend your Web server to do all the things listed above? That’s where Web application servers come into play. A Web application server is a piece of software that extends the Web server, enabling it to do things it can’t do by itself—kind of like teaching an old dog new tricks.

Here’s how it all works. When a Web server receives a request from a Web browser, it looks at that request to determine whether it is a simple Web page or a page that needs processing by a Web application server. It does this by looking at the MIME type (or file extension). If the MIME type indicates that the file is a simple Web page (for example, it has an .htm extension), the Web server fulfills the request and sends the file to the requesting browser as is. But if the MIME type indicates that the requested file is a page that needs processing by a Web application server (for example, it has a .cfm extension), the Web server passes it to the appropriate Web application server and returns the results it gets back rather than the actual page itself.

In other words, Web application servers are page preprocessors. They process the requested page before it’s sent back to the client (the browser), and in doing so they open the door to developers to do all sorts of interesting things on the server, such as:

• Creating guest books

• Conducting surveys

• Changing your pages on the fly based on date, time, first visit, and whatever else you can think of

• Personalizing pages for your visitors

• In fact, all the features listed previously

What Is ColdFusion?

Initially, developing highly interactive and data-rich sites was a difficult process. Writing custom Web-based applications was a job for experienced programmers only. A good working knowledge of Unix was a prerequisite, and experience with traditional development or scripting languages was a must.

But all that has changed. Adobe ColdFusion enables you to create sites every bit as powerful and capable, without a long and painful learning curve. In fact, rather than being painful, the process is actually fun!

So, what exactly is ColdFusion? Simply put, ColdFusion is an application server—one of the very best out there, as well as the very first. (ColdFusion actually defined the application server category back in 1995.)

ColdFusion doesn’t require coding using traditional programming languages, although traditional programming constructs and techniques are fully supported. Instead, you create applications by extending your standard HTML files with high-level formatting functions, conditional operators, and database commands. These commands are instructions to the ColdFusion processor and form the blocks on which to build industrial-strength applications.

Creating Web applications this way has significant advantages over conventional application development:

• ColdFusion applications can be developed rapidly because no coding is required, other than use of simple HTML style tags.

• ColdFusion applications are easy to test and roll out.

• The ColdFusion language contains all the processing and formatting functions you’ll need (and the capability to create your own functions if you run into a dead end).

• ColdFusion applications are easy to maintain because no compilation or linking step is required. (Files actually are compiled, but that happens transparently, as I’ll explain shortly.) The files you create are the files used by ColdFusion.

• ColdFusion provides all the tools you need to troubleshoot and debug applications, including a powerful development environment and debugger.

• ColdFusion comes with all the hooks necessary to link to almost any database application and any other external system.

• ColdFusion is fast, thanks to its scalable, multithreaded, service-based architecture.

• ColdFusion is built on industry-standard Java architecture, and supports all major standards and initiatives.

ColdFusion and Your Intranet, Extranet, and Portal

Everything explained here applies not just to Internet Web sites. Indeed, the benefits of ColdFusion apply to intranets, extranets, and portals, too.

Most companies have masses of information stored in various systems. Users often don’t know what information is available or even how to access it.

ColdFusion bridges the gap between existing and legacy applications and your employees. It gives employees the tools to work more efficiently.

ColdFusion Explained

You’re now ready to take a look at ColdFusion so you can understand what it is and how it works its magic.

And if you’re wondering why you went through all this discussion about the Internet and Web servers, here’s where it will all fit together.

The ColdFusion Application Server

ColdFusion is an application server—a piece of software that (usually) resides on the same computer as your Web server, enabling the Web server to do things it wouldn’t normally know how to do.

ColdFusion is actually made up of several pieces. The ColdFusion Application Server is the program that actually parses (reads and compiles) and processes any supplied instructions.

Instructions are passed to ColdFusion using templates. A template looks much like any HTML file, with one big difference. Unlike HTML files, ColdFusion templates can contain special tags that instruct ColdFusion to perform specific operations. Here is a sample ColdFusion template that you’ll use later in this book.

image

Earlier in this chapter, I said that Web servers typically return the contents of a Web page without paying any attention to the file contents.

That’s exactly what ColdFusion doesn’t do. When ColdFusion receives a request, it parses the template looking for special ColdFusion tags (they all begin with CF) or ColdFusion variables and functions (always surrounded by number [#] signs). HTML or plain text is left alone and is output to the Web server untouched. Any ColdFusion instructions are processed, and any existing results are sent to the Web server. The Web server can then send the entire output back to the requester’s browser. As explained earlier, the request file type tells the Web server that a request is to be handled by an application server. All ColdFusion files have an extension of .cfm or .cfml, like this:

http://www.forta.com/books/index.cfm

When ColdFusion is installed, it configures your Web server so it knows that any file with an extension of .cfm (or .cfml) is a ColdFusion file. Then, whenever a ColdFusion file is requested, the Web server knows to pass the file to ColdFusion for processing rather than return it.

It’s worth noting that ColdFusion doesn’t actually need a Web server because it has one built in. So as not to conflict with any other installed Web servers (like Apache and Microsoft IIS) the internal Web server runs on port 8500 or 8300 (depending on the type of installation performed) instead of the default port 80. During ColdFusion installation you’ll be asked whether you want to run ColdFusion in stand-alone mode (bound to the integrated Web server) or using an existing Web server. If you opt to use the internal Web server you’ll need to specify the port number in all URLs.

Note

The examples in this book use the internal Web server, so they include the port number. If you’re using an external Web server, just drop the port number from the URLs.

Caution

Adobe doesn’t recommend that the internal Web server (stand-alone mode) be used on production boxes. ColdFusion’s integrated HTTP server is intended for use on development boxes only.

The ColdFusion Markup Language

I said earlier that ColdFusion is an application server; that’s true, but that’s not all it is. In fact, ColdFusion is two distinct technologies:

• The ColdFusion Application Server

• The CFML language (including <cfscript>)

Although the ColdFusion Application Server itself is important, ColdFusion’s power comes from its capable and flexible language. ColdFusion Markup Language (CFML) is modeled after HTML, which makes it very easy to learn.

CFML extends HTML by adding tags with the following capabilities:

• Read data from, and update data to, databases and tables

• Create dynamic data-driven pages

• Perform conditional processing

• Populate forms with live data

• Process form submissions

• Generate and retrieve email messages

• Interact with local files

• Perform HTTP and FTP operations

• Perform credit-card verification and authorization

• Read and write client-side cookies

And that’s not even the complete list.

The majority of this book discusses ColdFusion pages (often called templates) and the use of CFML.

Linking to External Applications

One of ColdFusion’s most powerful features is its capability to connect to data created and maintained in other applications. You can use ColdFusion to retrieve or update data in many applications, including the following:

• Corporate databases

• Client-server database systems (such as Microsoft SQL Server and Oracle)

• Spreadsheets

• XML data

• Contact-management software

• ASCII-delimited files

• Images

• JavaBeans, JSP tag libraries, and EJBs

• .NET classes and assemblies

• Web Services

Extending ColdFusion

As installed, ColdFusion will probably do most of what you need, interacting with most of the applications and technologies you’ll be using. But in the event that you need something more, ColdFusion provides all the hooks and support necessary to communicate with just about any application or service in existence. Integration is made possible via:

• C and C++

• Java

• .NET

• COM

• CORBA

• XML

• Web Services

These technologies and their uses are beyond the scope of this book and are covered in detail in the sequels, ColdFusion Web Application Construction Kit, Volume 2: Application Development, and ColdFusion Web Application Construction Kit, Volume 3: Advanced Application Development.

Inside ColdFusion 9

ColdFusion 9 is the most remarkable ColdFusion to date, and is built on top of ColdFusion MX, the first completely redesigned and rebuilt ColdFusion since the product was first created back in 1995. Understanding the inner workings of ColdFusion isn’t a prerequisite to using the product, but knowing what ColdFusion is doing under the hood will help you make better use of this remarkable product.

I said earlier that ColdFusion is a page preprocessor—it processes pages and returns the results as opposed to the page itself. To do this ColdFusion has to read each file, check and validate the contents, and then perform the desired operations. But there is actually much more to it than that. In fact, within ColdFusion is a complete J2EE (Java 2 Enterprise Edition) server that provides the processing power ColdFusion needs.

Note

Don’t worry. You don’t need to know any Java at all to use ColdFusion.

First, a clarification. When people talk about Java they generally mean two very different things:

• The Java language is just that, a programming language. It is powerful and not at all easy to learn or use.

• The Java platform, a complete set of building blocks and technologies to build rich and powerful applications.

Of the two, the former is of no interest (well, maybe little interest) to ColdFusion developers. After all, why write complex code in Java to do what CFML can do in a single tag? But Java the platform? Now that’s compelling. The Java platform provides the wherewithal to:

• Access all sorts of databases

• Interact with legacy systems

• Support mobile devices

• Use directory services

• Create multilingual and internationalized applications

• Leverage transactions, queuing, and messaging

• Create robust and highly scalable applications

In the past you’d have had to write Java code in order to leverage the Java platform, but not any more. ColdFusion runs on top of the Java platform, providing the power of underlying Java made accessible via the simplicity of CFML.

Note

By default, the Java engine running ColdFusion is Adobe’s own award-winning J2EE server, JRun. ColdFusion can also be run on top of third-party J2EE servers like IBM WebSphere, BEA WebLogic, and JBoss. See Appendix A, “Installing ColdFusion and ColdFusion Builder,” for more information.

But don’t let the CFML (and CFM files) fool you—when you create a ColdFusion application you are actually creating a Java application. In fact, when ColdFusion processes your CFM pages it creates Java source code and compiles it into Java byte code for you, all in the background.

This behavior was first introduced in ColdFusion MX. Using ColdFusion you can truly have the best of both worlds—the power of Java, and the simplicity of ColdFusion, and all without having to make any sacrifices at all.

Powered by ColdFusion

You were probably planning to use ColdFusion to solve a particular problem or fill a specific need. Although this book helps you do just that, I hope that your mind is now racing and beginning to envision just what else ColdFusion can do for your Web site.

In its relatively short life, ColdFusion has proven itself to be a solid, reliable, and scalable development platform. ColdFusion 9 is the eleventh major release of this product, and with each release it becomes an even better and more useful tool. It is easy to learn, fun to use, and powerful enough to create real-world, Web-based applications. With a minimal investment of your time, your applications can be powered by ColdFusion.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.27.45