Web Application Success through JavaServer Pages - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Web Application Success through JavaServer Pages

Description:

Key Facts on JavaServer Pages (JSP) Server-side Java technology for dynamic content ... throws ServletException, IOException { response.setContentType('text/html' ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 22
Provided by: veze
Category:

less

Transcript and Presenter's Notes

Title: Web Application Success through JavaServer Pages


1
Web Application Success through JavaServer Pages
  • Vezen Wu
  • vw89_at_columbia.edu

2
Success Model for Web Applications
Simple to Use
Success
High Performance
Ease of Development
3
Key Facts on JavaServer Pages (JSP)
  • Server-side Java technology for dynamic content
  • Specification, not a product
  • Element-driven and scripting-based syntax
  • Supports Model-View-Controller (MVC) design

4
Case Study
  • CTA program requests a web-based application for
    students to check their information
  • Design a portal that requires students to enter a
    valid Student ID for access
  • Requirement for dynamic content

5
Query Screen
6
Dynamic Content
7
Validation
8
Error Page
9
Technologies for Dynamic Web Content
  • Active Server Pages (ASP)
  • PHP
  • Common Gateway Interface (CGI)
  • ColdFusion
  • Java Servlets
  • JavaServer Pages (JSP)

10
Java Servlet
  • public class StudentServlet extends HttpServlet
  • public void doGet(HttpServletRequest request,
    HttpServletResponse response)
  • throws ServletException, IOException
  • response.setContentType(text/html)
  • Printwriter out response.getWriter()
  • if (isValid() true)
  • out.println(lthtmlgt)
  • out.println( ltheadgt lttitlegtCTA Student
    Serviceslt/titlegt lt/headgt)
  • out.println( ltbodygt)
  • out.println( lth1gtCTA Student Services
    Portallt/h1gt)
  • out.println( ltp align\center\gtWelcome
    , ltfont color\red\gt getStudentName()
    lt/fontgt.)
  • out.println( Click lta
    href\profile.jsp\gtherelt/agt to access your
    profile.lt/pgt)
  • out.println( lt/bodygt)
  • out.println(lt/htmlgt)
  • private boolean isValid()
  • private String getStudentName()

HTML
11
The JSP Advantage
JSP Element
  • lt_at_ page language"java" contentType"text/html"
    gt
  • lthtmlgt
  • ltheadgt
  • lttitlegtCTA Student Serviceslt/titlegt
  • lt/headgt
  • ltbodygt
  • ltjspuseBean id"studentBean" scope"request"
    class"mybeans.StudentBean" /gt
  • lth1gtCTA Student Services Portallt/H1gt
  • ltp align"center"gt
  • Welcome, ltfont color"red"gtlt
    studentBean.getStudentName() gtlt/fontgt.
  • Click lta href"profile.jsp"gtherelt/agt to
    access your profile.
  • lt/pgt
  • lt/bodygt

12
HTTP Request/Response Model
Request
Client Web Browser
Server Web Server
Resource studentlookup.jsp
Response
13
JSP Processing
II Read
studentlookup.jsp
I GET /studentlookup.jsp
Client Web Browser
Server with JSP Container
III Generate
studentlookupServlet.java
VI HTTP/1.0 200 OK
Translation Phase (II, III, IV)
IV Compile
V Execute
V Execute
studentlookupServlet.class
Request Processing Phase (V)
14
Model-View-Controller (MVC) Design
15
MVC Design for the CTA Application
Request 1
View studentlookup.jsp studentconfirmation.jsp
Response 1
Response 2
Model StudentBean.java DatabaseBean.java
Client Web Browser
Forward
Controller studentvalidate.jsp
Request 2
16
JSP Anatomy
JSP Element
  • lt_at_ page language"java" contentType"text/html"
    gt
  • lthtmlgt
  • ltheadgt
  • lttitlegtCTA Student Serviceslt/titlegt
  • lt/headgt
  • ltbodygt
  • ltjspuseBean id"studentBean" scope"request"
    class"mybeans.StudentBean" /gt
  • lth1gtCTA Student Services Portallt/H1gt
  • ltp align"center"gt
  • Welcome, ltfont color"red"gtlt
    studentBean.getStudentName() gtlt/fontgt.
  • Click lta href"profile.jsp"gtherelt/agt to
    access your profile.
  • lt/pgt
  • lt/bodygt

Template Text
17
JSP Elements
  • Directive
  • lt_at_ page gt
  • Action
  • ltjspuseBeangt
  • ltjspsetPropertygt
  • ltjspgetPropertygt
  • ltjspforwardgt
  • ltjspparamgt
  • Scripting
  • lt gt Scriptlet
  • lt gt Expression

18
Controller JSP
  • lt_at_ page language"java" gt
  • ltjspuseBean id"studentBean" scope"request"
    class"mybeans.StudentBean"gt
  • ltjspsetProperty name"studentBean"
    property"" /gt
  • lt/jspuseBeangt
  • lt if (studentBean.isValid()) gt
  • ltjspforward page"studentconfirmation.jsp" /gt
  • lt else gt
  • ltjspforward page"studentlookup.jsp" /gt
  • lt gt

Directive Element
Scripting Element
Action Element
19
JavaBeans
  • Reusable software component
  • Conform to a design pattern
  • Model tier in MVC design
  • Value Beans and Utility Beans
  • IDE Support

20
JavaBean
  • public class StudentBean implements Serializable
  • private String studentID
  • private String studentName
  • public StudentBean()
  • public String getStudentID()
  • return studentID
  • public void setStudentID(String studentID)
  • this.studentID studentID
  • public boolean isValid()

Properties
Getter/Setter Methods
21
JSP The Winning Choice
  • Familiar interface
  • Access to benefits of the Java language
  • Streamlined development
Write a Comment
User Comments (0)
About PowerShow.com