Title: Web Application Success through JavaServer Pages
1Web Application Success through JavaServer Pages
- Vezen Wu
- vw89_at_columbia.edu
2Success Model for Web Applications
Simple to Use
Success
High Performance
Ease of Development
3Key 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
4Case 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
5Query Screen
6Dynamic Content
7Validation
8Error Page
9Technologies for Dynamic Web Content
- Active Server Pages (ASP)
- PHP
- Common Gateway Interface (CGI)
- ColdFusion
- Java Servlets
- JavaServer Pages (JSP)
10Java 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
11The 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
12HTTP Request/Response Model
Request
Client Web Browser
Server Web Server
Resource studentlookup.jsp
Response
13JSP 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)
14Model-View-Controller (MVC) Design
15MVC 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
16JSP 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
17JSP Elements
- Directive
- lt_at_ page gt
- Action
- ltjspuseBeangt
- ltjspsetPropertygt
- ltjspgetPropertygt
- ltjspforwardgt
- ltjspparamgt
- Scripting
- lt gt Scriptlet
- lt gt Expression
18Controller 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
19JavaBeans
- Reusable software component
- Conform to a design pattern
- Model tier in MVC design
- Value Beans and Utility Beans
- IDE Support
20JavaBean
- 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
21JSP The Winning Choice
- Familiar interface
- Access to benefits of the Java language
- Streamlined development