MY mENU


Friday, 30 March 2012

Writing the first JSP page

A JavaServer Page, technically speaking, is a web page which is embedded Java code. Java code is executed in the server side and merge with the static elements of the web page such as HTML tags... then returns the result which is plain old HTML code, JavaScript and CSS to the web browser.

This is the source code of our first JSP page which prints the simple famous greeting in programming world "Hello World" on the web browser.




JSP Page is composed of HTML and Java code. The Java code is embedded between thenotations <% and %> and it is called Scriptlet. Inside the scriptlet block, we call the method println of the out object to print the text "Hello World".

Thursday, 29 March 2012

JSTL Types

JSP standard tags library can be divided into four tag libraries which are:
  1. Core tags
  2. Internationalization (i18l) and formatting tags
  3. Relational database access tags
  4. XML processing tags
The goals of those tag library above are:
  • Simplify the task of writing JSP page by providing friendly XML base tags
  • Provide reusable logic from page's presentation
  • Make the JSP page easier to read and maintain
Core tags:
As its name imply, core tags provide the core functionality actions to JSP to make the most common actions easier to achieve in a more effective way. Core tags specify several actions such as displaying content based on condition, manipulating collections and URL managing. By using the core tags you'll never has to write a such small piece of scriptlet. (But you still need to know scriptlet to maintain legacy web applications and convert them to JSTL later on if you have to).

Internationalization(I18L) and formatting tags:
Those tags specify a series actions to make the web application multilingual. Those actions including managing resource bundle, locales and base names.

Relational database access tags:
Accessing database is a most major task of web applications. JSTL provides a list of standard tags to help you to manipulate data such as select, insert, update and delete from the relational databases.

XML processing tags:
XML becomes a standard of enterprise web application for exchanging data. ManipulateXML effectively therefore is very important for most web applications and of course JSTL also provides a list of tags for processing from XML parsing to XML transformation.

Introducing to JSP Standard Tag Library - JSTL

JSP is designed for the presentation layer in the web applications but it needs to contain the logic or code inside the page to control the way it presents the visual elements. Since JSP was borned, scriptlet has been used intensively therefore the JSP pages become messy and difficult to maintain. The HTML mixed with JSP scriptlet and opening and closing brace make JSP page even hard to extend.

In June 2002, JavaServer Pages standard library (JSTL) specification 1.0 was first released. JSTL provided a new ways for JSP author to work with different elements with standard friendly tags. The current version of the JSTL is 1.2 which was started in 2004 so we will use JSTL 1.2 for all the tutorials.