Pages

Showing posts with label JSP. Show all posts
Showing posts with label JSP. Show all posts

Thursday, February 10, 2011

J2EE Overview

Yes, there are so many other sites out there that provide J2EE Overviews but this is probably the most breif but yet complete one you'll find.

J2EE defines standards for developing multitier enterprise applications. It simplifies enterprise applications by basing them on standardised, modular components, and providing a set of services to those components. It handles many details of application behaviour automatically, without requiring complex programming.

Enterprise JavaBeans
EJB is a standard distributed object framework and component model. It defines several types of components: session beans, entity beans, message driven beans, which simplify application development by concealing application complexity and enabling the component designer to focus on business logic.

Servlets and JSPs
Servlets and Java Server Pages are complementary APIs, both providing a means for generating dynamic web content. Servlets are Java programs implementing the javax.servlet.Servlet interface and running in a Web/App server's servlet engine. JSPs contain a mixture of HTML and java scripts, JSP elements, and directives, and are compiled into Servlets by the JSP engine.

JDBC
JDBC is a set of interfaces allowing Java applications to access any database.

RMI
RMI is an API which allows Java objects to communicate remotely with other objects. Its equivalent from OMG is CORBA.

IDL
IDL is a standard platform-independent language used to define interfaces that object implemnetation provide and client objects call. It allows java objects to communicate with other objects in any language.

JMS
JMS API is a messaging standard that allows J2EE components to create, send, receive, and read messages. It enables distributed communication between components. The addition of the JMS API enhances the J2EE platform by simplifying enterprise development, allowing loosely coupled, reliable, asynchronous interactions among J2EE components and legacy systems capable of messaging.

JTA
JTA allows J2EE components to perform distributed transactions.

JavaMail
JavaMail API allows Java components to send and receive emails.

JAXP (includes JAXB which is sometimes mentioned separately?)
Java API for XML Processing allows java applications to parse and transform XML documents.

JNDI
Java Naming and Directory Interface is a protocol which provides a standard API to access naming and directory services. It allows Java applications to find any necessary resource in a standard way.


Why use J2EE?
  • It is a standardised and reliable software architecture
  • that gives a lot of flexibility
  • is well documented,
  • with low level services already implemented.

Monday, July 12, 2010

JSP Overview

JSP is a popular Java technology for web application development and is based on servlet technology. A JSP page is a text document that contains two types of text - static data which can be expressed in any text-based format (HTML, SVG, XML, etc) and JSP elements (standard JSP or XML) which construct dynamic content.

A JSP page services requests as a servlet. In an application server, the source for the servlet created from a JSP named myPage is myPage_jsp.java. Once the JSP has been translated and compiled, the page's servlet follows the standard servlet lifecycle.

Expressions that are evaluated immediately use the ${ } syntax. Expressions that are differed use the #{ } syntax. Immediate evaluation expressions are always read-only value expressions.

Implicit objects include:
  • PageContext
  • Servlet Context
  • Session
  • Request
  • Response
  • etc.
JSP technology directly supports JavaBeans components with standard JSP language elements:
  • The JSP:useBean element declares that the page will use a bean that is stored within and is accessible from the specified scope (application, session, request, or page)
  • jsp:setProperty
  • jsp:getProperty
Custom tags are user-defined JSP language elements that encapsulate recurring tasks. A tag handler is an object that implements a custom tag. When a JSP page containing a custom tag is translated into a servlet, the tag is converted into operations on a tag handler. The web container then invokes those operations when the JSP page's servlet is executed.

To declare that a JSP page will use tags defined in a tag library, include the taglib directive.

An Applet or JavaBeans component can be included in a JSP by using the jsp:plugin element.

Thursday, July 1, 2010

Struts Overview

Struts is an open-source web application framework for developing servlet/JSP based applications. It concentrates on the web tier, and aside from providing a simple JDBC connection pool, does not attempt to address persistence requirements.

It does, however, suggest the use of a domain object model and business logic beans, and its tag libraries include a number of tags for working with JavaBeans.

The Struts framework provides 3 key components:
  • A request handler provided by the application developer that is mapped to a standard URI.
  • A response handler that transfers control to another resource which completes the response.
  • A tag library that helps developers create interactive form-based applications with server pages.
Struts applications have 3 major components:
  • A servlet controller, which is provided by Struts
  • JSP pages (the view)
  • The application's business logic (the model)

Wednesday, June 30, 2010

Advantages of JSP

 JSP is a Java-based technology for creating dynamic web pages.

The following are some of the disadvantages of client-side scripting compared to JSP:
  • The user's browser must have scripting enabled, which is not always the case
  • The client-side code can only  be guaranteed to work for all the brower types it has been tested against. It can be a pain to code for multiple browsers
  • Client-side scripts have limited access to server-side resources (eg: databases)
  • Client-side scripting languages are less versatile than Java.
Some of the advantages of JSP over client-side scripting are as follows:
  • JSP enables clean separation of business logic from presentation
  • JSP is not limited to a specific platform, being Java-based and compiled into bytecode.
  • As JSP pages execute on the server it does not matter what browser or configuration the client has.
  • JSP has full access to server-side resources.
For all intents and purposes JSP is a sohpisticated Java Servlet. The main advantage of JSP over Java Servlets is the ease of coding - static text is achieved using HTML tags as opposed to a multitude of println statements.

Tuesday, June 29, 2010

Simple JSP Example

The following post provides an example of a simple JSP page and instructions on how to deploy and view it. It assumes the use of Eclipse and JBoss.

Create a new Dynamic Web Project in Eclipse called HelloWorld.You can accept the defaults, such as "WebContent" for the web root.

Create the file HelloWorld.jsp under the WebContent directory and paste the following code in:

<%@ page language="java" %>
<html>
<body>
<%
  for (int counter = 1; counter <= 10; counter++) {
%>
    Hello World!<br>
<%
  }
%>
</body>
</html>

Create a file called web.xml under the WEB-INF directory (which should have been automatically created under the WebContent directory) and paste in the following:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
</web-app>


Right-click the HelloWorld project folder and select Run As -&gt; Run on Server. Accept any defaults and run it on your local server. This should put a war file in C:\Apps\JBoss\jboss-5.1.0.GA\server\default\deploy (or equivalent).

Now go to http://localhost:8080/HelloWorld/HelloWorld.jsp and you should see:

Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!

Simple.
 
Powered by Blogger