New Technologies and What They Mean To You: Part 3
In part 2 of this series Jeremy talked about PHP, ASP and ColdFusion. In this article he explains what JSP and CGI are, providing advantages, disadvantages and examples for each.
New Technologies and What They Mean To You: Part 3 - JSP (Page 2 of 4 )
Definition
JSP is a Sun Micrososystems technology. You know Sun, the company behind Java? Good company, and JSP extends an already good technology. JSP is a free specification for extending Java Servlets to generate dynamic web pages on a web server.
Like most of our other technologies, JSP lets developers create dynamic HTML or XML pages that combine static page elements with dynamic content. This allows smart developers to separate the user bits like HTML from the logic bits, like the JSP code. JSP was created to simplify the Java Servlets technology, which we’ll cover in a future article, and to be simpler than the other offerings, like CGI, available at the time of its creation.
What It Really Is
So we understand that JSP is an extension of Java, for web pages, but what is it really about? For most people, that is Java’s biggest appeal; that they can tie into existing Java elements, and therefore save a lot of development time.
JSP is based on components. It uses JavaBeans and Enterprise JavaBeans (EJB) components which hold the business logic for an application, and it composes tags and a scripting platform for presenting the content generated and returned by the beans into HTML pages. The components structure means that non-Java developers can use JSP to manipulate beans that developers have built. On the other hand, Java developers can use these beans and Java in JSP pages for more advanced productions based on the beans.
A common JSP rollout would look something like this:
What is really happening in this process? A user calls a JSP page through their browser, so Resin (for instance), located on the web server, converts JavaScript, JSP tags, and HTML into segments of Java code, which the engine then consequentially arranges into a core Java servlet. This core servlet is therefore pre-assembled and works 'behind the scenes'. It is called every time that particular page is requested by a user, saving valuable recompiling time. The next time a user calls that page from their browser, because the JSP code has already been compiled, it does not have to convert the JavaScript, HTML, etc each time. That is, the servlet engine needs only to produce that servlet once, or after the last code change was updated.
JSP uses a combination of XML and CFM-like tags, as well as scripts written in Java, to generate page content. Applications written to the JSP specification can be run on compliant web servers, and web servers such as Apache, Netscape Enterprise Server, and Microsoft IIS that have had Java support added.
Advantages
Strong integration with JavaBeans and other elements
Ease of use for experienced Java developers
Rapid Application Development
Scales well to heavy loads
Cross-platform
Open Source
Disadvantages
JSP pages often run slower than similar pages such as PHP due to being more robust and intensive
Steeper learning curve than many other technologies
Here are some standard types of things you might find...
Including a file:
<%@ include file="dukebanner.html" %>
Conditionally including a file:
<% if ( request.getParameter("username") != null ) { include file="response.jsp" } %>
Custom JSP tag:
<jsp:setProperty name="numguess" property="*" />
Similar Technologies
Really, any Net-based scripting language is “similar” to JSP in that it fulfills the same goals, and we will look at most of these during the rest of this article series:
ColdFusion: ColdFusion is Macromedia’s offering for web-based dynamic content. While it isn’t technically “scripting”, as it is based on an HTML-like tag structure, it does fulfill the same goal of providing dynamic webpages.
PHP: Like JSP, PHP is cross-platform. In some ways it is simpler to develop, because it doesn’t require separate files for logic and procedures, and in other ways it is harder to develop in (for basically the same reason). PHP is a very strong language with an incredibly large and supportive community.
Links
There are many sites out there dedicated to JSP. Many of the best ones are provided by the suppliers and backers (IBM, Sun, etc) but there are also lots of other great resources, and we’ve gathered some of the best ones here: