cis 330 applied database systems
play

CIS 330: Applied Database Systems Lecture 10: Middle Tier - PowerPoint PPT Presentation

CIS 330: Applied Database Systems Lecture 10: Middle Tier Technologies: Servlets & JSP Alan Demers ademers@cs.cornell.edu Overview Internet concepts Three-tier architectures The presentation layer The middle tier


  1. CIS 330: Applied Database Systems Lecture 10: Middle Tier Technologies: Servlets & JSP Alan Demers ademers@cs.cornell.edu

  2. Overview • Internet concepts • Three-tier architectures • The presentation layer • The middle tier • CGI • Application servers • Servlets • JSP • Maintaining state

  3. Common Gateway Interface § What is CGI? • A general framework for creating server side web applications. • Instead of returning a static web document, web server returns the results of a program. • For example § browser sends the parameter: name=Ethan. § Web server passes the request to a Perl program. § Perl Program returns HTML that says, Hello, Ethan!

  4. CGI Overview C/Perl Web Name=Ethan Name=Ethan Web Program Server Browser Hello, Ethan! Hello, Ethan!

  5. Notes on CGI § The first mechanism for creating dynamic web sites. § What languages can you create CGI programs in? • Unix(tm) fork/exec heritage • Just about any language: C/C++, Perl, Java, etc.

  6. CGI Environment Variables § CGI includes a number of environment variables. • REMOTE_ADDR: Address of client browser • SERVER_NAME: The Server Host Name or IP Address • SERVER_SOFTWARE: Name and version of the server software. • QUERY_STRING: A String of GET or POST Form Variables. • etc.

  7. Overview • Internet concepts • Three-tier architectures • The presentation layer • The middle tier • CGI • Application servers • Servlets • JSP • Maintaining state

  8. Application Servers • Idea: Avoid the overhead of CGI • Pool of threads / processes • Manage connections • Enable access to heterogeneous data sources • Other functionality such as APIs for session management

  9. Application Server: Process Structure Process Structure HTTP Web Browser Web Server C++ Application JavaBeans JDBC Application Server DBMS 1 ODBC DBMS 2 Pool of Servlets

  10. Lecture Overview • Internet concepts • Three-tier architectures • The presentation layer • The middle tier • CGI • Application servers • Servlets • JSP • Maintaining state

  11. What is a Servlet? § Java’s answer to CGI. § Applet: a java program that runs within the web browser. § Servlet: a java program that runs within the web server. § The current standard for building web applications.

  12. Servlet Processing Client Request Regardless of the application, a servlet usually does the following: 2) Read any data sent by the user • Capture data submitted by an HTML form. 3) Look up any HTTP information • Determine the browser version, host name of client, cookies, etc. 4) Generate the Results • Connect to databases, connect to legacy applications, etc. 5) Format the Results • Generate HTML on the fly 6) Set the Appropriate HTTP headers • Tell the browser the type of document being returned or set any cookies. 7) Send the document back to the client

  13. Servlet Processing Client Request Database Web Web Java Browser Server Servlet

  14. What can you build with Servlets? § Search Engines § Personalization Systems § E-Commerce Applications § Shopping Carts § Product Catalogs § Intranet Applications § Groupware Applications: bulletin boards, file sharing, etc.

  15. Server Side Options § There are many options for creating server side applications. § We will examine some of these options briefly. § Understand servlets within the broader context of web development. § Understand the advantages and disadvantages of servlets.

  16. Server Side Options § Common Gateway Interface (CGI) § Fast CGI § Mod Perl § Server Extensions • NSAPI • ISAPI § ASP § PHP § Cold Fusion

  17. Common Features § All server side frameworks share a common set of features: • Read data submitted by the user • Generate HTML dynamically based on user input • Determine information about the client browser • Access Database systems • Exploit the HTTP protocol

  18. Decision Points § When evaluating which server side framework to use, you need to consider a number of critical factors: • Ease of development: § How easily can you build new applications? • Performance: § How fast can the framework respond to queries? • Scalability: § Can the framework scale to thousands, millions of users? • Security: § Are there any inherent security vulnerabilities?

  19. Option 1: CGI § Represents one of the earliest, practical methods for generating web content. § Primarily written in the Perl programming language. § Unfortunately, traditional CGI programs suffer from scalability and performance problems. § Let’s examine these two problems…

  20. CGI Architecture 1) Browser initiates request 2) Web server receives the request. 3) For each request, web server spawns a new operating system process to execute the CGI/Perl Program. Web Web Create Browser Server New process Perl/CGI

  21. CGI Architecture § For each browser request, the web server must spawn a new operating system process. Perl 1 Browser 1 Web Server Browser 2 Perl 2 Browser N Perl N

  22. CGI Architecture § Spawning a new operating system process for each request takes time and memory. § Hence, traditional CGI programs have inherent performance and scalability problems. § Every other server architecture tries to address these problems.

  23. Option 2: Fast CGI § Developed by Open Market as an option for developing faster, more scalable CGI programs. § Fast CGI works by creating a pool of processes for handling CGI requests. § When a CGI request comes in, Fast CGI picks one of the processes from the pool and assigns it to the task. § Without the overhead of creating new operating system processes, FastCGI is much faster than traditional CGI. § See http://www.fastcgi.com

  24. Option 3: Mod Perl § A module of the Apache Web Server (most popular web server on the planet!) § Embeds the Perl interpreter directly within the web server. § Perl programs are precompiled. § Because Perl is embedded within the Server, Mod Perl does not need to create a new process for each request. § Like FastCGI, Mod Perl is much faster than traditional CGI. § See http://perl.apache.org

  25. Option 4: Server Extensions § Several web servers provide extension APIs. • Netscape provides NSAPI • Microsoft provides ISAPA § Much like mod_perl, these programs run directly within the web server. § Hence, server extensions are much faster than traditional CGI. § Usually written in C/C++, and are not portable across web servers. § For example, if you develop to Netscape NSAPI, you cannot run it on ISAPI.

  26. Option 5: ASP.NET § Active Server Pages § Runs on Microsoft’s Web Server: Internet Information Server (IIS) § Programmers add ASP code directly into their HTML pages. § When a client requests a page, the Web Server takes the HTML page, runs the ASP code within the page, and returns a complete HTML page. § Faster than traditional CGI, but only works on Microsoft IIS.

  27. Option 6: Cold Fusion § Developed by Allaire Corporation. § Provides excellent database access and database tools. § Great platform for rapid prototyping and rapid development. § See http://www.allaire.com

  28. Option 7: PHP § Personal Home Pages (PHP) § An open source project written entirely by volunteers § Provides simple, but powerful database access. § Also great for rapid development § Growing very popular § See http://www.php.net

  29. Advantages of Servlets § Servlets have six main advantages: • Efficient • Convenient • Powerful • Portable • Secure • Inexpensive

  30. Advantage 1: Efficient § For each browser request, the servlet spawns a light weight thread. § This is faster and more efficient that spawning a new operating system process. § Hence, servlets have better performance and better scalability than traditional CGI.

  31. Advantage 2: Convenient § Servlets include built-in functionality for: • Reading HTML form data • Handling cookies • Tracking user sessions • Setting HTTP headers § Java is object oriented

  32. Advantage 3: Powerful § Servlets can talk directly to the web servers. § Multiple servlets can share data: • Particularly important for maintaining database connections. § Includes powerful techniques for tracking user sessions.

  33. Advantage 4: Portable § One of the advantages of Java is its portability across different operating systems. § Servlets have the same advantages. § You can write your servlets on Windows, then deploy them on UNIX. § You can run your servlets on any Java- enabled web server, with no code changes.

  34. Advantage 5: Secure § Traditional CGI programs have a number of known security vulnerabilities. § Hence, you usually need to include a separate Perl/CGI module to supply the necessary security protection. § Java has a number of built-in security layers. § Java servlets are considered more secure than traditional CGI programs.

  35. Advantage 6: Inexpensive § You can download free servlet kits for development use. § So you can get started for free! § Nonetheless, production quality servlet web servers can get quite expensive.

Recommend


More recommend