Server Side: JSP and Java Servlets - PowerPoint PPT Presentation

About This Presentation
Title:

Server Side: JSP and Java Servlets

Description:

Server Side: JSP and Java Servlets Chris North cs3724: HCI Client-side Method: Download and run program on client Examples: Java applets, javascript, activeX, css ... – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 16
Provided by: ChrisN165
Category:
Tags: jsp | java | server | servlets | side

less

Transcript and Presenter's Notes

Title: Server Side: JSP and Java Servlets


1
Server SideJSP and Java Servlets
  • Chris North
  • cs3724 HCI

2
Client-side
  • Method
  • Download and run program on client
  • Examples
  • Java applets, javascript, activeX, css, plugins,
  • Good for
  • dynamic interaction,
  • Reducing server load
  • Animations, processing intensive
  • Server security, crash protection

3
Server-side
  • Method
  • Dynamically generated web pages on server
  • Download resulting html page to client
  • Examples
  • JSP, Java Servlets, php, asp, cgi, perl,
    includes, C
  • Good for
  • database interaction
  • Broad client compatibility, customize to
    browser/OS
  • Data synchro, collaborative apps
  • Access control
  • Small downloads
  • No installs
  • Code security, hack protection
  • Client security
  • Screen scraping
  • simple interaacations

4
Example Data-Driven Websites
  • Websites that provide access to
  • Lots o data
  • Dynamic data
  • Customized views of data
  • E.g. ebay.com
  • Scripts map data to html

Database
html
5
Server-side processing
Client (Browser) 1. User click 5. Display
html
Server (Web server) 2. Receive HTTP
request 3. Execute script 4. Send html result
URL requestscript.jsp
Script.jsp
Response html page
html
6
Example
Amazon.com server
Books.exe
Cart.exe
Purchase.exe
  • Charges credit card
  • Displays thankyou
  • Link back to books
  • Shows books list
  • Add to cart
  • View cart button
  • Displays cart contents
  • Delete items
  • Purchase button

7
Problems
  • Many simultaneous users
  • No state data maintained
  • Client not in sync with server (e.g. back button)


Books.exe
Cart.exe
Purchase.exe
8
Different than GUI programming!
  • One user (per executable)
  • Global state data
  • Client server

Shopping.exe Books window Cart window Purchase
window
9
Problems
  • Myscript.exe starts from scratch each time
  • Each page request is completely independent
  • No state data maintained between requests
  • Who is the user?
  • What is his data?
  • Where is he in the application?
  • How to maintain state info across page accesses?
  • Pile all state data into hidden form items
  • Cookies
  • Store state data in a database, index by unique
    user id

10
Java Servlets
  • Html
  • Link URL/servlet
  • Form post
  • Servlet
  • Init()
  • Destroy()
  • doGet()
  • doPost()

11
example
  • Out.println(lthtmlgtltbodygt)
  • Out.println(ltpgthello world)
  • Out.println(new java.util.Date( ))
  • Out.println(lt/bodygtlt/htmlgt)
  • Browser recieves
  • lthtmlgtltbodygt
  • Hello world 200pm, March 28, 2002
  • lt/bodygtlt/htmlgt

12
Java Server Pages (JSP)
  • Html code
  • New tags lt gt and lt gt
  • Myscript.jsp
  • lthtmlgtltbodygt
  • Hello world lt new java.util.Date() gt
  • lt/bodygtlt/htmlgt
  • Client receives
  • lthtmlgtltbodygt
  • Hello world 200pm, March 28, 2002
  • lt/bodygtlt/htmlgt

13
Processing form input
  • Global object request, session
  • lt session.putValue(username,
    request.getParameter(UserName)) gt
  • lthtmlgtltbodygt
  • Thanks for giving us your name, lt
    session.getValue(username) gt
  • lt/bodygtlt/htmlgt

14
Session Data
  • Global object session
  • lthtmlgtltbodygt
  • Hello,
  • lt session.getValue(username) gt
  • lt/bodygtlt/htmlgt
  • Client receives
  • lthtmlgtltbodygt
  • Hello, Chris
  • lt/bodygtlt/htmlgt

15
JSP objects
  • Application
  • Config
  • Out
  • Request
  • Response
  • Session
Write a Comment
User Comments (0)
About PowerShow.com