What is J2EE - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

What is J2EE

Description:

Oracle 9ias built in servlet/JSP support. Weblogic built in ... Oracle's OC4J built in servlet/JSP support. Additional Resources. http://java.sun.com ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 20
Provided by: All153
Category:
Tags: j2ee

less

Transcript and Presenter's Notes

Title: What is J2EE


1
What is J2EE?
  • J2EE (Java 2 Platform Enterprise Edition) is a
    combination of tools and java technologies
    available to simplify application development and
    deployment on the Internet.
  • Technologies include Servlets, JSP(s), Enterprise
    Java Beans and JDBC to name a few.
  • Tools include the JDK and Forte for Java

2
What are Java Servlets?
  • Servlets are Java technology's replacement for
    CGI programming. They are java programs that run
    on a web server or J2EE container and provide
    dynamic web content.
  • Commonly used to extend the functionality of a
    web server.
  • Built upon a request-response model (doGet,doPost
    methods)
  • Access to Java API(s) bundled with JDK such as
    JDBC.

3
Advantages of Servlets over CGI
  • Efficient/Scalable JVM is loaded once and each
    HTTP request is handled by a lightweight java
    thread. CGI executes a heavyweight OS process for
    each user request. The overhead of this OS
    process degrades performance and impacts
    scalability.
  • Powerful simplified session tracking (session
    API provides support for getting track of state
    using cookies, URL rewriting and hidden form
    fields) and data sharing that allows easy
    implementation of things like connection pooling.
  • Portable runs on any web server with servlet
    support. (All of them)

4
Client Server Architecture
5
HttpServlet Class
  • All Servlet classes extend the HttpServlet
    abstract class
  • HttpServlet simplies writing HTTP servlets by
    providing a framework for handling the HTTP
    protocol.
  • Since HttpServlet is abstract, you must extend it
    and implement at least one of the methods
    (doGet,doPost)
  • Your Servlet class is declared as public so the
    web server or J2EE container can access it.

6
Typical Servlet Class
  • import javax.servlet. // contains generic
    (protocol-independent) servlet classes
  • import javax.servlet.http. // contains HTTP
    servlet classes
  • public class TypicalServletClass extends
    HttpServlet
  • public void init() throws ServletException
  • public void doPost (HttpServletRequest request,
    HttpServletResponse response)
  • throws ServletException,
    IOException
  • public void doGet (HttpServletRequest request,
    HttpServletResponse response)
  • throws ServletException,
    IOException
  • public void destroy()

7
Life of a Servlet
  • Life cycle is controlled by the web server or
    container in which the servlet is deployed.
  • (1) If instance of servlet class does not exist
  • Loads the servlet class
  • Creates an instance of the servlet class
  • Initializes the servlet instance by calling the
    init() method.

8
Life of a Servlet (Cont)
  • (2) Invokes a service method (doGet(), doPost())
    and passing in a request and response object.
  • (3) If the servlet needs to be garbage collected
    (removed from memory), then the destroy() method
    is called by the web server/J2EE container
    (finally)

9
doGet vs. doPost Method
  • doGet is called in response to an HTTP GET
    request.
  • A GET request is a request to get a resource from
    the server.
  • This is the case of a browser requesting a web
    page.
  • It also happens with HTML Forms that specify the
    METHOD"GET" in the FORM tag.
  • doPost is called in response to an HTTP POST
    request.
  • A POST request is a request to post or send form
    data to a resource on the server.
  • Both methods are called by the default
    (superclass) implementation of service in the
    HttpServlet base class.
  • You override one or both to perform your
    servlet's actions.

10
So Which One do I implement?
  • doGet has some limitations in the amount of data
    that can be passed as parameters
  • doGet data is sent as a part of the URL and thus
    sensative data may be exposed
  • Most implement doPost and and doGet placing the
    code that will perform some action in doPost and
    calling doPost from doGet passing in the request
    and response objects.
  • public void doGet(HttpServletRequest request,
    HttpServletResponse response) throws
    ServletException, IOException
  • doPost(request, response)

11
Simple Servlet Example
  • import java.io. // for system input and output
  • import javax.servlet. // contains generic
    (protocol-independent) servlet classes
  • import javax.servlet.http. // contains HTTP
    servlet classes
  • public class SimpleServletExample extends
    HttpServlet
  • public void doPost(HttpServletRequest request,
    HttpServletResponse response) throws
    ServletException, IOException
  • response.setContentType("text/html")
  • PrintWriter out response.getWriter()
  • out.println("ltHTMLgtltHEADgtltTITLEgtWelcome to
    Bradshaw Marinalt/TITLEgtlt/HEADgt")
  • out.println("ltBODYgtltH1gtWelcome to Bradshaw
    Marinalt/H1gt ltH3gtCurrent Time ")
  • out.println(new java.util.Date())
  • out.println("lt/H3gtlt/BODYgtlt/HTMLgt")

12
How to call Servlet from HTML
  • ltHTMLgt
  • ltHEADgt
  • ltTITLEgtCall a Simple Servletlt/TITLEgt
  • lt/HEADgt
  • ltBODYgt
  • ltH1gtCall a Simple Servlet that Generates the
    Welcome Pagelt/H1gt
  • ltFORM name"form1" method"post"
    action"SimpleServletExample"gt
  • ltpgt
  • ltinput type"submit" valueCall Servlet"gt
  • lt/pgt
  • lt/FORMgt
  • lt/BODYgt
  • lt/HTMLgt

13
What are Java Server Pages
  • Java Server Pages (JSP) is a technology that
    allows you to mix static and dynamic HTML
    content. (very similar to ASP)
  • Web content rendered by CGI programs are mostly
    static. Even with servlets you generate the
    entire web page with your java code. JSPs allow
    the two to be separated. Presentation is standard
    HTML and java is written within special tags (lt,
    gt)

14
Advantages of Java Server Pages
  • vs. Active Server Pages (ASP). ASP is a similar
    technology from Microsoft. The advantages of JSP
    are twofold. First, the dynamic part is written
    in Java, not Visual Basic or other MS-specific
    language, so it is more powerful and easier to
    use. Second, it is portable to other operating
    systems and non-Microsoft Web servers.
  • vs. Pure Servlets. JSP doesn't give you anything
    that you couldn't in principle do with a servlet.
    But it is more efficient to write the
    presentation in HTML than to have many println
    statements that generate the HTML. You can
    separate the tasks among different people.

15
Advantages of Java Server Pages
  • vs. Server-Side Includes (SSI). SSI is a
    widely-supported technology for including
    externally-defined pieces into a static Web page.
    JSP is better because it lets you use servlets
    instead of a separate program to generate that
    dynamic part. SSI is only intended for simple
    inclusions, not complex tasks that use form data
    and make database connections.
  • vs. JavaScript. JavaScript can generate HTML
    dynamically on the client. This is a useful
    capability, but only handles situations where the
    dynamic information is based on the client's
    environment. With the exception of cookies, HTTP
    and form submission data is not available to
    JavaScript. And, since it runs on the client,
    JavaScript can't access server-side resources
    like databases.

16
Simple JSP Example
  • lt_at_ page import"java.util." gt
  • ltHTMLgt
  • ltHEADgtltTITLEgtWelcome to Bradshaw
    Marinalt/TITLEgtlt/HEADgt
  • ltBODYgt
  • ltH1gtWelcome to Bradshaw Marinalt/H1gt
  • ltH3gtCurrent Time
  • ltnew java.util.Date()gt
  • lt/H3gt
  • lt/BODYgt
  • lt/HTMLgt

17
Deploying Servlets and JSP(s)
  • Web Servers
  • Microsoft IIS servlet/JSP plugin
  • Oracle 9ias built in servlet/JSP support
  • Weblogic built in servlet/JSP support
  • J2EE Lightweight containers for Java
  • Tomcat - built in servlet/JSP support
  • Oracles OC4J built in servlet/JSP support

18
Additional Resources
  • http//java.sun.com/
  • http//java.sun.com/products/servlet/index.html
  • http//java.sun.com/products/jsp/
  • http//jakarta.apache.org/tomcat/

19
Demos
  • SimpleServletExample display Welcome screen
    with HTML and make a call to the java.util
    package to get the current date and time.
  • SimpleJSP.jsp - display Welcome screen with
    HTML and make a call to the java.util package to
    get the current date and time.
  • OracleQueryServlet displays a list of employees
    from a specific department (demonstrates both get
    and post requests)
  • SimpleOracleQueryJSP1.jsp - execute query using
    statement class.
  • SimpleOracleQueryJSP2.jsp - execute query using
    preparedStatement class and bind variables.
  • CallSPSample.jsp - execute a stored procedure
    using the callableStatement class and bind
    variables.
Write a Comment
User Comments (0)
About PowerShow.com