0% found this document useful (0 votes)
41 views

Server Side: JSP and Java Servlets: Chris North cs3724: HCI

This document compares and contrasts client-side and server-side web development. It discusses how client-side uses downloaded programs like Java applets and JavaScript, while server-side dynamically generates web pages on the server using technologies like JSP, PHP, and ASP. Server-side is better for database interaction, broad compatibility, and maintaining state across page requests. The document then provides an example of how JSP can be used to build data-driven websites and maintain state using session objects.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Server Side: JSP and Java Servlets: Chris North cs3724: HCI

This document compares and contrasts client-side and server-side web development. It discusses how client-side uses downloaded programs like Java applets and JavaScript, while server-side dynamically generates web pages on the server using technologies like JSP, PHP, and ASP. Server-side is better for database interaction, broad compatibility, and maintaining state across page requests. The document then provides an example of how JSP can be used to build data-driven websites and maintain state using session objects.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 15

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, plugins,
• Good for:
• dynamic interaction,
• Reducing server load
• Animations, processing intensive
• Server security, crash protection
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
Example: Data-Driven Websites
• Websites that provide access to:
• Lots o data
• Dynamic data Database
• Customized views of data
• E.g. ebay.com

• Scripts map data to html html


Server-side processing

Client (Browser) Server (Web server)

URL request
1. User click 2. Receive HTTP request
script.jsp
3. Execute script
Script.jsp
Response
5. Display html 4. Send html result
html page
html
Example
Amazon.com server

Books.exe Cart.exe Purchase.exe

•Shows books list •Displays cart contents •Charges credit card


•Add to cart •Delete items •Displays ‘thankyou’

•View cart button •Purchase button •Link back to books


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

Books.exe Cart.exe Purchase.exe


Different than GUI programming!
• One user (per executable)
• ‘Global’ state data
• Client = server

Shopping.exe

Books window
Cart window
Purchase window
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
Java Servlets
• Html:
• Link: URL/servlet
• Form post
• Servlet
• Init()
• Destroy()
• doGet()
• doPost()
example
Out.println(“<html><body>”);
Out.println(“<p>hello world”);
Out.println(new java.util.Date( ));
Out.println(“</body></html>”);

• Browser recieves:
<html><body>
Hello world 2:00pm, March 28, 2002
</body></html>
Java Server Pages (JSP)
• Html + code
• New tags <% %> and <%= %>
• Myscript.jsp:
<html><body>
Hello world <%= new java.util.Date() %>
</body></html>

• Client receives:
<html><body>
Hello world 2:00pm, March 28, 2002
</body></html>
Processing form input
• Global object: request, session

<% session.putValue(“username”,
request.getParameter(“UserName”)) %>

<html><body>
Thanks for giving us your name, <%=
session.getValue(“username”) %>
</body></html>
Session Data
• Global object: session
<html><body>
Hello,
<%= session.getValue(“username”) %>
</body></html>

• Client receives:
<html><body>
Hello, Chris
</body></html>
JSP objects
• Application
• Config
• Out
• Request
• Response
• Session

You might also like