# Presentation: 608977

## JSP - What is it Good For?

- GSFC Webmasters
- January 24, 2002
- Chris Durachka / Code 585
- cdurachk@pop500.gsfc.nasa.gov

**Notes:**
Jsp is another tool/language to be added to your already overflowing box of tools.  What I do not want to do today is to get into a long drawn out debate as to what server-side internet language is superior.  Each language has it’s own set of pros and cons.

Roughly 20 percent of a recent Forrester Research survey found that companies use at least 2 different application servers using a myriad of internet language tools to create their web applications.  Is this a result of teams being created with different skill sets, various departments stove piping applications to fit their needs, or a little bit of both.  What all of these applications/web sites have in common is they all serve dynamic content in response to a user’s input with a database back-end.  Oh yeah, these applications must also be robust and scalable to meet future needs.

The Giga Information Group polled 120 IT executives in early December to find 78% of the group viewed J2EE (Java 2 Enterprise Edition – JSP) server software as the most effective platform for building and deploying Web services.  Microsoft’s .Net got 22% of the votes.  To should how rapidly developing the JSP/Java architecture is gaining in popularity the same poll was done in early Feb 01, where Microsoft came out the No. 1.

An important thing to take from this talk is not only when to use, but more importantly when not to use JSP.  And if possible combine the pros from JSP, Cold Fusion, and Perl to create a more dynamic, robust, and scalable internet application.

How many people here are using Perl, Cold Fusion, JSP,....

With all of that said....  What is JSP good for??????

## Agenda

- Overview of JSP
- JSP Architecture
- Providers of JSP Server Engines
- Who is Using JSP
- Compare JSP to Other Tools
- Pros and Cons of JSP
- Examples
- JAVABeans
- Links/Questions

## JSP Overview - History

- Earlier dynamic web pages were developed  with CGI
- Web Applications eventually outgrew CGI because of the following:
- Datasets became large
- Increased traffic on sites
- Trouble maintaining state and session information
- Performance bottlenecks
- Can involve proprietary APIs

## JSP Overview History (Cont’d)

- Microsoft Saves the Day?
- Active Server Pages (ASP) are released that are:
- Pre-coded server extensions
- Easily integrates with ODBC
- Gives developers simple server-side scripting to access the server
- Upside for Microsoft, downside for us, ASP is limited to only Microsoft platforms

## JSP Overview History (Cont’d)

- In response to ASP, Sun Microsystems gave the world Java Server Pages (JSP)
- Entirely based in Java Programming language
- JSP supports the same modularity, reusability, platform-independence, and access to Java APIs as Java
- Gives developers the advantages of developing in Java in a more relaxed script-like environment
- The biggest difference between ASP and JSP is the approach taken in the development efforts
- JSP is designed to be platform and server independent, created from a broader community of tool, server, and database vendors
- ASP relies primarily on Microsoft technologies

## JSP Overview - Software

- With a foundation in Java, JSP
- Threads incoming requests
- Supports the definition of tags that abstract functionality within a page in a library
- Interacts with a wide array of databases
- Serves dynamic content in a persistent and efficient manner
- Initially the server automatically builds, compiles, and starts the servlet, from then on the servlets are stored in the web server’s memory in Java byte code
- Extends the same portability, large class library, object-oriented code methodology, and robust security measures that have made Java a top choice
- Does not require a Java programmer

## Architecture

## JSP Engine Open Source Providers(the short list)

- Acme -  Acme Utilities
- _[http://www.acme.com/java/software/](http://www.acme.com/java/software/)_
- Bit Mechanic -  GNU Server Pages
- _[http://www.bitmechanic.com/projects/gsp/](http://www.bitmechanic.com/projects/gsp/)_
- Evidian/Objectweb - JOnAS (ObjectWeb)
- _[http://www.objectweb.org/jonas/](http://www.objectweb.org/jonas/)_
- Caucho – Resin
- _[http://www.caucho.com/](http://www.caucho.com/)_

- Jakarta Apache –Tomcat v4
- _[http://jakarta.apache.org/tomcat/](http://jakarta.apache.org/tomcat/)_
- KLOMP.org - GNU JSP
- _[http://klomp.org/gnujsp/](http://klomp.org/gnujsp/)_
- Mort Bay – Jetty
- _[http://jetty.mortbay.com/jetty/](http://jetty.mortbay.com/jetty/)_
- Tagtraum -  jo! and JSPExecutor
- _[http://www.tagtraum.com/](http://www.tagtraum.com/)_
- W3.org -  Jigsaw
- http://www.w3.org/Jigsaw/

## Who is using JSP?(Customers of Caucho)

- altavista.com
- http://www.altavista.com
- half.com
- http://www.half.com
- E-Loan
- http://www.e-loan.com
- iWon
- http://www.iwon.com
- Jguru
- http://www.jguru.com
- State of Maine
- http://www.state.me.us

- petsmart.com
- http://www.petsmart.com
- ya.com
- http://www.ya.com
- BizRate
- http://www.bizrate.com
- salesforce.com
- http://www.salesforce.com
- listen.com
- http://www.listen.com
- State of Utah
-  http://www.state.ut.us

**Notes:**
The question I always ask myself and typically the presenter is .... Okay JSP is great, but is anyone using it.
I notices the other day that the Chase web site is driven by JSP.  The new Civil Servant timecard system and the goddard portal is being developed in JSP.
Note Half.com and the use of jsp and coldfusion

## Comparison of JSP to...

**Notes:**
PHP, ColdFusion, ASP and JSP are all popular server-side scripting middle for Web database. Which one is the best choice for you? Let's compare their features in the following table: 

## Comparison of JSP to (Cont’d) ...

**Notes:**
For small non-profit organizations, PHP/MySQL combo is a good choice. 
For enterprises, ColdFusion excels for its ease to implement and design, and its functionality.
For companies already invested heavily on Microsoft systems, ASP is the default choice.
For development of information systems facing future, JSP is a promising tool. Allaire will bridge ColdFuson and JSP in their next-generation Web-DB environment.

## Pros and Cons

- Pros
- Efficient
- Convenient
- Server engines typically have built-in infrastructures to handle parsing/decoding HTML form data, reading/setting HTTP headers, session tracking
- Powerful
- Java behind the scene
- Portable
- Write once, run anywhere
- Inexpensive
- Various free or inexpensive engines available

- Cons
- Need for a Server Engine
- Another engine to maintain
- Un-acceptably by the client machine
- Virtual hosting of unrelated sites on a single machine can cause problems (choose your server engine wisely)
- High Learning Curve
- Steeper learning curve than Cold Fusion

**Notes:**
Java servlets are more efficient, easier to use, more powerful, more portable, and cheaper than traditional CGI and many alternative CGI-like technologies. (PHP, ASP and Perl as discussed above). 
Here is a breakdown of the advantages of servlets: 
Efficient. With traditional CGI, a new process is started for each HTTP request. If the CGI program does a relatively fast operation, the overhead of starting the process can dominate the execution time. With servlets, the Java Virtual Machine stays up, and each request is handled by a lightweight Java thread, not a heavyweight operating system process. Servlets also have more alternatives than do regular CGI programs for optimizations, such as caching previous computations and keeping database connections open. 
Convenient. Besides the convenience of being able to use a familiar language, servlets have an extensive infrastructure for automatically parsing and decoding HTML form data, reading and setting HTTP headers, handling cookies, tracking sessions, and many other such tasks. 
Powerful. Java servlets let you easily do several things that are difficult or impossible with regular CGI. For one thing, servlets can talk directly to the Web server (regular CGI programs cannot). This simplifies operations that need to look up images and other data stored in standard places. Servlets can also share data among each other, making useful things like database connection pools easy to implement. They can also maintain information from request to request, simplifying things like session tracking and caching of previous computations. 
Portable. Servlets are written in Java and follow a well-standardized API. Consequently, servlets written for, say iPlanet Enterprise Server can run virtually unchanged on Apache, Microsoft IIS, or WebSTAR. Servlets are supported directly or via a plug-in on almost every major Web server. Inexpensive. Various free or very inexpensive Web servers available are good for "personal" use or low-volume Web sites. But with the major exception of Apache, which is free, most commercial-quality Web servers are relatively expensive. But once you have a Web server, no matter the cost of that server, adding servlet support to it (if it does not come preconfigured to support servlets) is usually inexpensive or even free
Here are some disadvantages:   
Need for the Server or the Servlet Engine. Servlets need a Server inorder to run, the server can be of high cost or not, However, in almost every case, you can use a cheap or free application server or servlet engine. 
Un-acceptability by the Client Machine, in that case we have to use cgi to get the job done.  Servlets are not such a good choice if you are virtual hosting multiple unrelated sites on a single machine 
Learning Cure, the learning curve for JSP can be quite steep.

## Examples‘Hello World’

- <html>
- <!-JSP name: Hello.JSP**  **Written by Chris -->
- <head>
- <title>Hello1.jsp</title>
- </head>
- <body>
- Hello World
- </body>
- </html>
**The browser displays: ‘Hello World’**

## Examples‘Rectangle Problem’

- <html>
- <!--- JSP name: area problem --
- <head>
- </head>
- <body>
- <% int height = 4, width = 7 ; %>
- The area of the rectangle is <%= height * width %>
- </body>
- </html>
**The browser displays: 'The area of the rectangle is 28'.**** **
**Note: Java and JSP are very case sensitive**

## Examples‘Random Numbers’

- <html>
- <!--- JSP name: Random Numbers --
- <body><H1>Your Personal Random Numbers</h2>
- <P>Here are your personal random numbers:
- <OL>
- <%
- java.util.Random r = new java.util.Random(  );
- for (int i=0; i<5; i++) {
-        out.print("<LI>");
-        out.println(r.nextInt(  ));
- }
- %>
- </OL>
- </body></html>

## Examples‘Random Numbers’ (Cont’d)

- The browser displays:
- Your Personal Random Numbers
- Here are your personal random numbers:
-    1.524033632
-    2.-1510545386
-    3.1167840837
-    4.-850658191
-    5.-1203635778

## JSP and JavaBeans

- A JavaBean is a Java Class file that creates an object
- Defines how to create an Object, retrieve and set properties of the Object

**JSP**

**JavaBeans**

**Get Bean Value**

**Set Bean Value**

## JSP and JavaBeans (Cont’d)

- JavaBeans can store data
- JavaBeans can perform complex calculations
- JavaBeans can hold business logic
- JavaBeans can handle Database Connectivity and store data retrieved from them
- JavaBeans facilitate
- Reuse of code
- Debugging process
- Separating code from content
- Beans are not for user interfaces

**Notes:**
For the ASP userssimiliar to the Active X/COM Objects
Perl similar to packing/subroutines

## Some Good Links

- Jguru.com
- _[http://www.jguru.com](http://www.jguru.com/)_ - main page has nice search of the FAQ, Forums, etc...
- _[http://www.jguru.com/faq/JSP](http://www.jguru.com/faq/JSP)_  their main JSP FAQ page
- Jspinsider.com
- _[http://www.jspinsider.com](http://www.jspinsider.com/)_ - articles, tutorials, links
- _[http://www.jspinsider.com/content/rcarnes/jspb_intro.view](http://www.jspinsider.com/content/rcarnes/jspb_intro.view)_ - on-line course/tutorial on JSP
- Other Tutorials
- _[http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/](http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/)_  basis of the book Core Servlets and JavaServer Pages (Sun Microsystems Press and Prentice Hall, May 2000) by Marty Hall
- Sun’s Java Site – JSP
- Forum active  _[http://forum.java.sun.com/forum.](http://forum.java.sun.com/forum.jsp?forum=45)__[jsp](http://forum.java.sun.com/forum.jsp?forum=45)__[?forum=45](http://forum.java.sun.com/forum.jsp?forum=45)_
- archive-http://archives.java.sun.com/archives/servlet-interest.html
- Sun’s Java Site – APIs
- Java Std Ed _[http://java.sun.com/j2se/1.3/docs/](http://java.sun.com/j2se/1.3/docs/api/index.html)__[api](http://java.sun.com/j2se/1.3/docs/api/index.html)__[/index.html](http://java.sun.com/j2se/1.3/docs/api/index.html)_  essential java
- Java Enterprise Edition _[http://java.sun.com/j2ee/j2sdkee/](http://java.sun.com/j2ee/j2sdkee/techdocs/api/index.html)__[techdocs](http://java.sun.com/j2ee/j2sdkee/techdocs/api/index.html)__[/](http://java.sun.com/j2ee/j2sdkee/techdocs/api/index.html)__[api](http://java.sun.com/j2ee/j2sdkee/techdocs/api/index.html)__[/index.html](http://java.sun.com/j2ee/j2sdkee/techdocs/api/index.html)_  enterprise-class server side applications

## Questions?