Welcome!

Java Authors: Liz McMillan, Walter H. Pinson, III, Maureen O'Gara, Yakov Werde, Tony Bishop

Related Topics: Java

Java: Article

How To Pick A Programming Language: Back To Two Tiers and Plain JSP

How do you tackle all details when the transition from static HTML to dynamic HTML needs to be made?

A two-tier system is easier to design and allows for faster development. When developing JSP, it's also possible to use reusable components. JSP can easily include other JSP at compile time or runtime. This lets you create standard JSP to be reused. When the code is imbedded in the JSP, it can still be easily maintained; it's just a different type of process. When the code is split into components, there's a well-defined level of abstraction. Each component does a specific job, such as database access or user-interface output, and the components fit together to build the application.

When a JSP contains code that handles all aspects of an application, understanding each component's function in the page becomes more cerebral than code-based. Code for database queries is mixed with HTML. Code for application flow is mixed with data display logic. Although it sounds like a nightmare to experienced Java developers working in the MVC world, it's an example of how many sites are developed using JSP and languages like PHP, Perl, or ASP. Sites written this way can be easily put together because there's less structure to implement. The addition of a multi-tier structure sacrifices time spent on additional coding for easier long-term maintenance by multiple developers.

Development
Web development using any of the available languages leads to similar results. In the end, you have a combination of code and HTML. With Perl, you'll see more code writing out HTML, whereas with the other scripting languages you'll see HTML with embedded code. JSP, PHP, and ASP will look very similar, the main difference being the code language used. All offer similar features such as easy interfaces to parameter retrieval or cookie management. Flow control elements, such as FOR loops, also have similar implementations. These similarities make the transition to JSP development easier for experienced programmers who've been using a different language.

JSP permits full use of the Java programming language. Whatever can be done in a Java class, such as a servlet, can be done in a JSP. This gives the programmer great flexibility. It also enables experienced programmers to integrate object-oriented elements easily into their JSP development. Helper classes can be easily implemented to make common and repetitive tasks easier, such as database access. Although these helper classes can be used, you don't have to. Developing dynamic sites with JSP can be done with simple JSP structures that handle all the design elements. A JSP can handle all of the database access, for example. It can retrieve a database connection from a connection pool or create its own, make database queries, display output, and finally close the connection. And if you can do it in another language, you can do it in Java.

Conclusion
When looking at Java and other languages and their evolution over the past few years, it's easy to see how complex it's gotten. Layer upon layer of complexity has been added, and Java is the leader in this field of change. This complexity, and the time and effort needed to grasp it properly, can lead new developers away from Java and into alternatives like PHP, ASP, ColdFusion, and the other Web scripting languages. It can also lead developers down a path to unnecessary architecture bloating. Small or mid-sized projects can be developed in JSP without complicated architectures like Model-View-Controller. MVC and similar architectures have a time and place, but it's important to understand that Java development doesn't have to be complicated and can be done as easily as in PHP. Unfortunately, Java development carries the stigma of complicated development tools and complicated object-oriented code. These misconceptions and misunderstanding of Java development drives people away. The flexibility of Java and the environment in which it's developed should be bringing them to it instead.

More Stories By Brian Russell

Brian A. Russell is a senior software engineer for Priority Technologies, Inc. in Omaha, Nebraska.

Comments (10) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Infernoz 09/03/05 03:34:19 AM EDT

You have got to be kidding about embedded Java code and lots of Smart Tags in JSP pages (Model 1), Informix Web DataBlade showed me the incredible stupidity of this approach i.e. massive pages, nasty error trapping and logging code, and appalling maintenance costs, so don't do it, however tempting, you will regret it! If you use JSP, use at least Model 2 JSP and consider using higher level engines for larger sites e.g. Java Faces, Velocity etc.

Infernoz 09/03/05 03:33:47 AM EDT

You have got to be kidding about embedded Java code and lots of Smart Tags in JSP pages (Model 1), Informix Web DataBlade showed me the incredible stupidity of this approach i.e. massive pages, nasty error trapping and logging code, and appalling maintenance costs, so don't do it, however tempting, you will regret it! If you use JSP, use at least Model 2 JSP and consider using higher level engines for larger sites e.g. Java Faces, Velocity etc.

maxmath 08/09/05 03:45:39 AM EDT

I agree with a lot of points with the author. JSP is a good language to develop small and simple application. It's a pity that it is no more supported by Sun and the developper community.

George Jempty 08/02/05 06:52:22 AM EDT

Plain JSPs, with business, data access, and view logic rolled into one, should never be used for anything but the quickest and dirtiest prototype:
http://htmatters.net/htm/1/2005/08/Plain-JSPs-Just-Plain-Wrong.cfm

Dev Null 07/26/05 10:54:55 AM EDT

One thing you failed to mention when using JSP is the need for an application server. PHP on the other hand uses just the HTTP Server on a system with PHP installed. I have been a J2EE architect and developer for many years and recently when trying to get something professionally looking up and running, it is easier to forget about the app server and use something like PHP. Just my 2 cents.

Don Babcock 07/22/05 08:54:35 AM EDT

Good article. It's worth noting that there is another free solution out there that marries the best of Java and the simplicity of tag based languages. While ColdFusion CF is Java under the covers, New Atlanta makes a competing product (Blue Dragon) that follows the CF language model (tag based) and for which the low end version is free. That version has about 80 plus percent of the features and certainly all that is needed if what is in view is moving from a site that is HTML to dynamic content. It is available in both Windows and Linux incarnations and is quite powerful. The major cost of a web site over time is maintenance and CF is a very "friendly" alternative to JSP. It can be readily understood by those coming primarily from HTML as it uses the same tag paradigm. Like ColdFusion, it uses Java as the core engine so it can easily be extended to incoroporate in Java anything needed that doesn't come natively. It's worth a look if you are looking at low cost (free is hard to beat.) I've ported a lot of code between commercial CF which we use at work and Blue Dragon which I use on my own sites with complete portability. The Macromedia folks are always upping the ante by adding new things but CF has been around for so long that the core things used to build dynamic sites are commodity features share by both products and very nearly identical in function. About the only thing required is adjustments in the SQL if you use a different underlying DB but that's true everywhere.

digereedoo 07/22/05 02:35:33 AM EDT

Unfortunately, I disagree with the whole choose a programming language theme. There is only one programming language left and thats Java.

But more than that, patterns like MVC and the complexity they foist on these "regular" programming languages are telling us something.

WHAT? Are they telling us? They are telling us that our programming languages are HORRIBLE at implementing real solutions.

They are great at HELLO WORLD, pounding expressions endlessly in loops and the FAKE bank account example.

But we have a really, really hard time delivering solid stuff with them.

So why is that? If these patterns are so indispensable then maybe the patterns have evolved further than the languages that we program in, because if it was that clear I would be programming in MVC not Java.

But alas, its not. We are using the wrong hammer no matter what we do these days and we just try to make things "maintainable" for our corporate bosses and espouse APIs and frameworks to cure our ill at every turn. Ah the joy of marketing.

Buts let not kid ourselves into believeing we have anything less than a full scale mess on our hands..Java, EJB, XML, (provide your own acronym here) or not.

Mark Wallace 07/20/05 07:26:11 AM EDT

I agree that small dynamic sites can ease development by keeping it to JSPs only. Applying a pattern of separating display code and action code into separate JSP files (e.g. http://fusebox.org) allows you to still have well-strutured code (MVC) that can be maintained by a team while still only working in JSP's.

Dan Novik 07/18/05 03:26:13 PM EDT

How long it will take for Sun & co to realize that the development time is also a resource?

Java Developer's Journal 07/18/05 12:32:08 PM EDT

Back to Two Tiers and Plain JSP. There comes a time, for many Web sites, when the transition from static HTML to dynamic HTML has to be made. Whether it's a static company Web site that needs to become a dynamic online store, or a simple collection of family pictures that's become too large to manage with HTML alone, a decision has to be made to move to an environment that makes it easier to build and maintain the site. Deciding to use server-side programming to create your site on-the-fly can become the only option, but what language you decide to use can be a difficult and important decision.