What is Advance Java J2EE

Post on 15-Jul-2015

154 views 3 download

Tags:

transcript

Byjavawithease

Java EE Containers

Java Sevlet 3.0 Java Server Pages 2.2 Java Server Faces 2.0 Enterprise JavaBeans 3.1 JavaMail 1.4

Java Sevlet 3.0 Java Server Pages 2.2 Java Server Faces 2.0 Enterprise JavaBeans 3.1 JavaMail 1.4

A servlet is a Java programming language class used to extend the capabil i t ies of servers that host applications accessed via a request-response programming model

A servlet is a Java programming language class used to extend the capabil i t ies of servers that host applications accessed via a request-response programming model

import java.io.*;import javax.servlet.*;import javax.servlet.http.*;

public class HelloWorld extends HttpServlet{   public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException {  response.setContentType("text/html");  PrintWriter pw = response.getWriter();  pw.println("<html>");  pw.println("<head><title>Hello World</title></title>");  pw.println("<body>");  pw.println("<h1>Hello World</h1>");  pw.println("</body></html>");}}

import java.io.*;import javax.servlet.*;import javax.servlet.http.*;

public class HelloWorld extends HttpServlet{   public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException {  response.setContentType("text/html");  PrintWriter pw = response.getWriter();  pw.println("<html>");  pw.println("<head><title>Hello World</title></title>");  pw.println("<body>");  pw.println("<h1>Hello World</h1>");  pw.println("</body></html>");}}

<web-app> <servlet>  <servlet-name>Hello</servlet-name>  <servlet-class>HelloWorld</servlet-class> </servlet>

 <servlet-mapping> <servlet-name>Hello</servlet-name> <url-pattern>/HelloWorld</url-pattern> </servlet-mapping>

</web-app>

<web-app> <servlet>  <servlet-name>Hello</servlet-name>  <servlet-class>HelloWorld</servlet-class> </servlet>

 <servlet-mapping> <servlet-name>Hello</servlet-name> <url-pattern>/HelloWorld</url-pattern> </servlet-mapping>

</web-app>

JavaServer Pages (JSP) is a Java technology that helps Software Developers, serve dynamically generated pages, based on HTML, XML, or other document types

JavaServer Pages (JSP) is a Java technology that helps Software Developers, serve dynamically generated pages, based on HTML, XML, or other document types

<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd">

<html>    <head>        <title>JSP Page</title>    </head>    <body>        <h1>            <%                out.println("Hello World");            %>        </h1>    </body></html>

<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd">

<html>    <head>        <title>JSP Page</title>    </head>    <body>        <h1>            <%                out.println("Hello World");            %>        </h1>    </body></html>

There are five kinds tags that is available in JSP

 Directive Tag Declaration Tag Expression Tag Scriplet

There are five kinds tags that is available in JSP

 Directive Tag Declaration Tag Expression Tag Scriplet

JSP directives provide directions and instructions to the container, telling it how to handle certain aspects of JSP processing.A JSP directive affects the overall structure of the servlet class. It usually has the following form:

<%@ directive attr ibute="value" %>

JSP directives provide directions and instructions to the container, telling it how to handle certain aspects of JSP processing.A JSP directive affects the overall structure of the servlet class. It usually has the following form:

<%@ directive attribute="value" %>

Types of directive tag:

JSP Declarations:A declaration declares one or more variables or methods that you can use in Java code later in the JSP file. You must declare the variable or method before you use it in the JSP file.

Following is the syntax of JSP Declarations:

<%! declaration; [ declaration; ]+ ... %> You can write XML equivalent of the above syntax as fol lows:

<jsp:declaration> code fragment </jsp:declaration>

Following is the syntax of JSP Declarations:

<%! declaration; [ declaration; ]+ ... %> You can write XML equivalent of the above syntax as follows:

<jsp:declaration> code fragment </jsp:declaration>

A JSP expression element contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file.

JSP Expression:

Following is the syntax of JSP Expression:

<%= expression %>

Following is the syntax of JSP Expression:

<%= expression %>

The Scriptlet:A scriptlet can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language.

Following is the syntax of Scriptlet:<% code fragment %>You can write XML equivalent of the above syntax as follows:

<jsp:scriptlet> code fragment </jsp:script let>

Following is the syntax of Scriptlet:<% code fragment %>You can write XML equivalent of the above syntax as follows:

<jsp:scriptlet> code fragment </jsp:scriptlet>

JSP comment marks text or statements that the JSP container should ignore. A JSP comment is useful when you want to hide or "comment out" part of your JSP page.

JSP Comments:

Following is the syntax of JSP comments:<%-- This is JSP comment --%> Following is the syntax of JSP comments:<%-- This is JSP comment --%>

<HTML><BODY><FORM METHOD=POST ACTION="SaveName.jsp">What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR>What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4><P><INPUT TYPE=SUBMIT></FORM></BODY></HTML>

<HTML><BODY><FORM METHOD=POST ACTION="SaveName.jsp">What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR>What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4><P><INPUT TYPE=SUBMIT></FORM></BODY></HTML>

public class UserData { String username; String email; int age;

public void setUsername( String value ) { username = value; }

public void setEmail( String value ) { email = value; }

public void setAge( int value ) { age = value; }

public class UserData { String username; String email; int age;

public void setUsername( String value ) { username = value; }

public void setEmail( String value ) { email = value; }

public void setAge( int value ) { age = value; }

public String getUsername() { return username; }

public String getEmail() { return email; }

public int getAge() { return age; } }

public String getUsername() { return username; }

public String getEmail() { return email; }

public int getAge() { return age; } }

<jsp:useBean id="user" class="UserData" scope="session"/><jsp:setProperty name="user" property="*"/> <HTML><BODY><A HREF="NextPage.jsp">Continue</A></BODY></HTML>

<jsp:useBean id="user" class="UserData" scope="session"/><jsp:setProperty name="user" property="*"/> <HTML><BODY><A HREF="NextPage.jsp">Continue</A></BODY></HTML>

<jsp:useBean id="user" class="UserData" scope="session"/> <HTML><BODY>You entered<BR>Name: <%= user.getUsername() %><BR>Email: <%= user.getEmail() %><BR>Age: <%= user.getAge() %><BR></BODY></HTML>

<jsp:useBean id="user" class="UserData" scope="session"/> <HTML><BODY>You entered<BR>Name: <%= user.getUsername() %><BR>Email: <%= user.getEmail() %><BR>Age: <%= user.getAge() %><BR></BODY></HTML>

The Enterprise JavaBeans architecture or EJB for short is an architecture for the development and deployment of component-based robust, highly scalable business applications. These Applications are scalable, transactional, and multi-user secure.

The Enterprise JavaBeans architecture or EJB for short is an architecture for the development and deployment of component-based robust, highly scalable business applications. These Applications are scalable, transactional, and multi-user secure.

Benefits of EJBEJB simplifies the development of small and large enterprise applications. The EJB container provides system-level services to enterprise beans, the bean developer can just concentrate on developing logic to solve business problems.

EJB simplifies the development of small and large enterprise applications. The EJB container provides system-level services to enterprise beans, the bean developer can just concentrate on developing logic to solve business problems.

Session Bean Entity BeanMessage-Driven Bean

Session Bean Entity BeanMessage-Driven Bean

Session is one of  the EJBs and it  represents a single client inside the Application Server. Stateless session is easy to develop and its efficient. As compare to entity beans session beans require few server resources.

A session bean is similar to an interactive session and is not shared; it can have only one client, in the same way that an interactive session can have only one user. A session bean is not persistent and it is destroyed once the session terminates. 

Session is one of  the EJBs and it  represents a single client inside the Application Server. Stateless session is easy to develop and its efficient. As compare to entity beans session beans require few server resources.

A session bean is similar to an interactive session and is not shared; it can have only one client, in the same way that an interactive session can have only one user. A session bean is not persistent and it is destroyed once the session terminates. 

Stateless Session Beans A stateless session bean does not maintain a conversational state for the client. When a client invokes the method of a stateless bean, the bean's instance variables may contain a state, but only for the duration of the invocation.

Stateful Session BeansThe state of an object consists of the values of its instance variables. In

a stateful session bean, the instance variables represent the state of a unique client-bean session. Because the client interacts ("talks") with its bean, this state is often called the conversational state. 

Stateless Session Beans A stateless session bean does not maintain a conversational state for the client. When a client invokes the method of a stateless bean, the bean's instance variables may contain a state, but only for the duration of the invocation.

Stateful Session BeansThe state of an object consists of the values of its instance variables. In

a stateful session bean, the instance variables represent the state of a unique client-bean session. Because the client interacts ("talks") with its bean, this state is often called the conversational state. 

Session Bean Types

Entity beans are persistence java objects, whose state can be saved into the database and later can it can be restored from Data store. Entity bean represents a row of the database table.

Entity beans are persistence java objects, whose state can be saved into the database and later can it can be restored from Data store. Entity bean represents a row of the database table.

Message Driven Bean is an enterprise bean that can be used by JEE applications to process the messages asynchronously. Message Driven Bean acts as message consumer and it receives JMS messages.

Message Driven Bean is an enterprise bean that can be used by JEE applications to process the messages asynchronously. Message Driven Bean acts as message consumer and it receives JMS messages.