Tuesday, December 22, 2009

New Releases - GlassFish v3 and Java EE 6



Wednesday, December 16, 2009

What is JAX-RS (Java API for RESTful Web Services)?


(JAX-RS) - RESTful Web Services

Lightweight RESTful approaches have emerged as a popular alternative to SOAP-based technologies for deployment of services on the Internet. However, development of such services with the Java platform is significantly more complex than development of SOAP-based services, due to the low-level nature of the current platform APIs.

The goal of the Java API for RESTful Web Services (JAX-RS) is to provide a high-level declarative programming model for such services that is easy to use and encourages development according to REST tenets. Services built with this API are deployable with a variety of Web container technologies and benefit from built-in support for best-practice HTTP usage patterns and conventions.
For more details see the link below :


Overview of JSTL SQL Tags (JSTL Tags part - 3)


SQL Tags:
The tags are used to achieve common database related tasks such as selection, insertion, deletion, updation from within the jsp pages, without using any java code.

1). <sql:query>
This tag is used to query databases.
Syntax:
<sql:query sql="sqlQuery"
var="varName" [scope="{page|request|session|application}"]
[dataSource="dataSource"]
[maxRows="maxRows"]
[startRow="startRow"] />

2). <sql:update>
This tag is used to execute SQL INSERT, UPDATE or DELETE statement. It is also used to execute Data Definition Language statements.
Syntax:
<sql:update sql="sqlUpdate"
[dataSource="dataSource"]
[var="varName"]
[scope={page|request|session|application}" ] />

3). <sql:setDataSource>
This tag is used to export a data source either as a scoped variable or as the data source configuration variable.
<sql: setDataSource
{dataSource="dataSource" | url = "jdbcUrl"
[driver="driverClassName"]
[user="userName"]
[password="password"]}
[var="varName"]
[scope="{page|request|session|application}"] />

4). <sql:param>
This tag is used to set the values of parameter.
Syntax:
<sql:param value="value"/>
5). <sql:dateParam>
Sets the values of parameter markers in a SQL statement for values of type java.util.Date. It also works as a subtag of <sql:query> and <sql:update> tags.
Syntax:
<sql:dateParam value = "value" [type="{timestamp|time|date}"] />
6). <sql:transaction>
This tag is used to set a transaction context for <sql:query> and <sql:update> subtags.
Syntax:
<sql:transaction [dataSource="dataSource"]
[isolation=isolationLevel]>
<sql:query> and <sql:update> statements
</sql:transaction>

isolationLevel ::= "read_committed"
| "read_uncommitted"
| "repeated_read"
| "serializable"


Monday, December 14, 2009

Overview of JSTL Formatting Tags (JSTL Tags part - 2)


Formatting Tags

The formatting tags are used for internationalization and localization of the jsp pages. Internationalization provides support for various languages and data formats. By localization web applications becomes capable of supporting specific regions or locale.



1). <fmt:message>
This tag is used to output locale sensitive strings. The param subtag along with message provides an argument to the compound message in parent message tag. One param tag must be specified for each variable in the compound message or pattern. Replacement takes place in order of the param tags.
Syntax: <fmt:message key = "messageKey"
[bundle="resourceBundle"]
[var="varName"]
[scope="{page|request|session|application}"] />

2). <fmt:setLocale>
This tag is used to set the default locale within a specific JSP scope.
<fmt:setLocale value = "en_US" />
3). <fmt:bundle>
This tag is used to create an i18n localization context to be used by its body content.
Syntax: <fmt:bundle basename = "basename="basename"
[prefix="prefix"]>
body content
</fmt:bundle>

It creates an i18n localization context and loads its resource bundle into that context. The name of the resource bundle is specified with the basename attribute.
4). <fmt:setBundle>
This tag creates an i18n localization context and loads its resource bundle into that context. The name of the resource bundle is specified with the basename attribute.
Syntax: <fmt:setBundle basename = "basename"
[var="varname"]
[scope="{page|request|session|application}"]/>

5). <fmt:param>

This tag is used for parametric replacement to <fmt:message> tag.
Syntax: <fmt:param value="messageParameter"/>

6). <fmt:requestEncoding>

This tag is used to set the request's character encoding
Syntax: <fmt:requestEncoding [value="charsetName"]/>

7). <fmt:timeZone>

This tag is used to specify the time zone in which time information is to be formatted or parsed in its body content.
Syntax: <fmt:timeZone value="timeZone">
body content
</fmt:timeZone>

8). <fmt:setTimeZone>

This tag is used to store specified time zone in a scoped variable or the time zone configuration variable.
Syntax: <fmt:setTimeZone value="timeZone"
[var="varName"]
[scope="{page|request|session|application}"] />

9). <fmt:formatNumber>

This tag is used to format a numeric value in a locale-sensitive or customized manner as a number, currency etc.
Syntax: <fmt:formatNumber value = "numericValue"
[type="{number|currency|percent}"]
[pattern="customPattern"]
[currencyCode="currencyCode"]
[currencySymbol="currencySymbol"]
[goupingUsed="{true|false}"]
[scope="{page|request|session|application}"] />

10). <fmt:parseNumber>
This tag is used to parse the string representation of numbers, currencies, and percentages that were formatted in a locale-sensitive or customized manner.
Syntax: <fmt:parseNumber value="numericValue"
[type="{number|currency|percent}"]
[pattern="customPattern"]
[parseLocale="parseLocale"]
[integerOnly="{true|false}"]
[var="varName"]
[scope="{page|request|session|application}"]/>

11). <fmt:formatDate>
This tag is used to format date and time according to the locale.
Syntax: <fmt:formatDate value="date"
[type="{time|date|both}"]
[dateStyle="{default|short|medium|long|full}"]
[timeStyle="{default|short|medium|long|full}"]
[pattern="customPattern"]
[timeZone="timeZone"]
[var="varName"]
[scope={page|request|session|application}"] />

12). <fmt:parseDate>
Parses the string representation of dates and time that were formatted for a specific locale.
Syntax: <fmt:parseDate value = "dateString"
[type="{time|date|both}"]
[dateStyle="{default|short|medium|long|full}"]
[timeStyle="{default|short|medium|long|full}"]
[pattern="customPattern"]
[timeZone="timeZone"]
[parseLocale="parseLocale"]
[var="varName"]
[scope={page|request|session|application}"] />


Overview of JSP Initialization Parameters


Here is the procedure to specify the initialization parameters for JSP
Web.xml - is used to specify the initialization parameters.
init.jsp - is used to retrieve and show the initialized parameters



Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<servlet>
<servlet-name>InitJSP</servlet-name>
<jsp-file>/init.jsp</jsp-file>
<init-param>
<param-name>testParam</param-name>
<param-value>hello from web.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>InitJSP</servlet-name>
<url-pattern>/Init</url-pattern>
</servlet-mapping>
</web-app>

The HTML that is used to access the above parameters…


init.jsp
<html>
<head>
<title>Initialization Parameters in JSP</title>
</head>
<body>
Initialization parameter retrieved from the web.xml is:
<br>
<%= pageContext.getServletConfig().getInitParameter("testParam") %>
</body>
</html>