J2EE Overview - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

J2EE Overview

Description:

J2EE Overview Web Programming CSCI 4300 J2EE multi-tier architecture Servlet: Java class loaded into Web server JSP page: enhanced HTML page that is compiled into a ... – PowerPoint PPT presentation

Number of Views:129
Avg rating:3.0/5.0
Slides: 23
Provided by: Defa342
Category:
Tags: j2ee | applets | java | overview

less

Transcript and Presenter's Notes

Title: J2EE Overview


1
J2EE Overview
  • Web Programming
  • CSCI 4300

2
J2EE multi-tier architecture
  • Servlet Java class loaded into Web server
  • JSP page enhanced HTML page that is compiled
    into a servlet for deployment
  • JavaBean data holding class (part of Model in
    MVC)

3
J2EE Architecture
  • Applets and special clients downloaded, connect
    back to server
  • Enterprise Java Beans long-term,
    application-scope data storage and business logic

4
Web Application Layout
5
Mirroring packages with directories
6
Web Application Descriptor, web.xml
  • Defines servlets and maps them to URL paths
  • Declares the welcome file for the app
  • Specifies pages or servlets to handle various
    errors
  • Provides initialization parameters to servlets
  • Provides links to external resources such as
    database connections

7
Web.xml prolog
  • lt?xml version"1.0" encoding"ISO-8859-1"?gt
  • lt!DOCTYPE web-app PUBLIC "-//Sun Microsystems,
    Inc.//DTD Web Application 2.3//EN"
  • http//java.sun.com/dtd/web- app_2_3.dtdgt
  • You can validate your web.xml using the W3C
    validator service (recommended1)
  • When you change your web.xml, you must ask Chris
    or me to reload your web-app

8
Web.xml root element
  • ltweb-appgt
  • web application contents.
  • lt/web-appgt
  • Can contain
  • Servlet definitions
  • Servlet paths
  • Parameters
  • Etc, etc.

9
Servlet element
  • ltservletgt
  • ltservlet-namegtGonzoServletlt/servlet-namegt
  • ltservlet-classgtcs4300.Gonzolt/servlet-classgt
  • lt/servletgt
  • Or
  • ltservletgt
  • ltservlet-namegtGonzoServletlt/servlet-namegt
  • ltjsp-pagegtgonzo.jsplt/jsp-pagegt
  • lt/servletgt

10
Servlet-mapping element
  • ltservlet-mappinggt
  • ltservlet-namegtGonzoServletlt/servlet-namegt
  • lturl-patterngt/gonzolt/url-patterngt
  • lt/servlet-mappinggt
  • If the web application root is http//ganesha.cs.u
    ga.edu/myapp,
  • GonzoServlet is accessed at
  • http//ganesha.cs.uga.edu/myapp/gonzo

11
Welcome page
  • ltwelcome-file-listgt
  • ltwelcome-filegt
  • index.jsp
  • lt/welcome-filegt
  • lt/welcome-file-listgt
  • Index.jsp is the file served at the URL
    http//ganesha.cs.uga.edu/myapp

12
Error page elements
  • lterror-pagegt
  • lterror-codegt404lt/error-codegt
  • ltlocationgtnotFound.jsplt/locationgt
  • lt/error-pagegt
  • lterror-pagegt
  • ltexception-typegt
  • org.xml.sax.SaxParseException
  • lt/exception-typegt
  • ltlocationgtparseError.jsplt/locationgt
  • lt/error-pagegt

13
Basic JSP page
  • lt_at_ page contentType"text/html charsetUTF-8"
    gt
  • lthtmlgt
  • ltheadgt
  • ltStatic HTML codegt
  • Declarations
  • Java expressions
  • Scriptlets (chunks of Java code)
  • Try to minimize the mixing of HTML with Java
    (violates Model 2 architecture)

14
Declaration, scriptlet, and expression
  • lt! int i String userName gt
  • lttable border1gt
  • lt for (i0iltuserName.lengthi) gt
  • lttrgtlttdgtlti1 gt lt/tdgt
  • lttdgt ltuserNamei gt lt/tdgtlt/trgt
  • lt gt
  • lt/tablegt

15
Equivalent HTML from previous
  • lttable border1gt
  • lttrgtlttdgt1lt/tdgtlttdgtMichael Adamslt/tdgtlt/trgt
  • lttrgtlttdgt2lt/tdgtlttdgtDan Everettlt/tdgtlt/trgt
  • lttrgtlttdgt1lt/tdgtlttdgtHunter Thompsonlt/tdgtlt/trgt
  • lt/tablegt
  • But note that we try to avoid such mixing of Java
    and HTML!

16
Model 2 Architecture (MVC)
17
Helper Object Scopes
18
JavaBean
  • Helper class that holds information
  • Separates Java code from HTML
  • Implements Model component of MVC architecture
  • Useful for holding session data

19
JSP Address Book Interface
20
JavaBean Example
  • Store functionality user enters name -email pair
    for storage in bean
  • Fetch functionality user enters name, bean
    replies with email

21
JSP-Bean communication
  • Make ltINPUTgt element names in JSP correspond to
    variable names in Bean
  • Write Bean class with setX() and getX() setter
    and getter methods
  • ltjspsetPropertygt sends inputs to Bean
  • ltjspgetPropertygt gets values from Bean

22
Acknowledgements
  • J2EE architecture diagrams Sun J2EE tutorial,
    http//java.sun.com/j2ee/1.4/docs/tutorial/doc/ind
    ex.html
  • Object scopes jGuru Java Server Pages
    fundamentals, http//java.sun.com/developer/online
    Training/JSPIntro/contents.htmlJSPIntro6_3
Write a Comment
User Comments (0)
About PowerShow.com