Presentation is loading. Please wait.

Presentation is loading. Please wait.

How CGI and Java Servlets are Run By David Stein 14 November 2006.

Similar presentations


Presentation on theme: "How CGI and Java Servlets are Run By David Stein 14 November 2006."— Presentation transcript:

1 How CGI and Java Servlets are Run By David Stein 14 November 2006

2 CGI

3 What is CGI? Common Gateway Interface server side program or script used to process data entered into an online form commonly referred to as a script

4 What is needed in order to create and run a CGI program? Computer with: 1. Internet access 2. Web browser 3. Text editor Access to a web server Knowledge of HTML and a programming/scripting language

5 What languages are associated with CGI Any programming language that can be run or executed in a server environment – C – C++ – Visual Basic – PHP – Perl – Java – Etc…

6 How is a CGI program run? 1. User requests a web page 2. Web server responds with request 3. User enters data into an HTML form and sends it back to the web server HTML form (Get or Post) 4. Server receives the request from the user and processes the form Compiled or Interpreted 5. Server responds with appropriate data to the user

7 CGI Process Internet HTTP Request HTTP Response Script Processed

8 Example Form HTTP request for a webpage HTTP Request – Request Line Command, URL (http://cslab103.cs.edinboro.edu/~d301987s/it665/handle_pres _form.html), and HTTP version – Request Header Variety of optional info (i.e. web browser and date) – Request Body Information that needs to be sent to the server – Data typed into the form

9 HTTP Response Response Status – HTTP version #, server, status code (200 or 400), and a response phrase Response Header – Variety of optional info (web server used, date, exact URL of page, etc….) Response Body – Webpage

10 Processed PHP Script Your Feedback <?php // handle_php.php //This page receives the data from feedback.html. //It will receive: title, name, email, response, comments, and submit print "Thank you $title $name for your comments. "; print "You stated that you found this example to be $response and added: $comments"; ?>

11 Java Servlets

12 What are Java Servlets? Modules of Java code that run in a server application (similar to an applet on the client side) Counterpart to dynamic web technologies such as PHP, ASP.Net, etc…

13 Uses of Java Servlets Processing/storage of data submitted by an HTML form Provide dynamic content to a web server Managing of state information on top of stateless HTTP

14 Java Servlet Process Internet HTTP Request HTTP Response Developer with JSDK Java VM (servlet engine) Client

15 Example Java Servlet Code import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloClientServlet extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println(" Hello Client! "+ " Hello Client! "); out.close(); } public String getServletInfo() { return "HelloClientServlet 1.0 by Stefan Zeiger"; }

16 Servlet Output

17 Servlet Advantages Over CGI Servlet does not run in a separate process – (removes overhead of creating a new process) Servlet stays in memory between requests Servlet can be run in restrictive Sandbox

18

19 Sources PHP (Visual Quick Start Guide) – By Larry Ullman http://www.novocode.com/doc/servlet- essentials http://www.novocode.com/doc/servlet- essentials http://java.sun.com/j2ee/tutorial/1_3- fcs/doc/Servlets.html http://java.sun.com/j2ee/tutorial/1_3- fcs/doc/Servlets.html http://java.sun.com/products/servlet/whitepap er.html http://java.sun.com/products/servlet/whitepap er.html


Download ppt "How CGI and Java Servlets are Run By David Stein 14 November 2006."

Similar presentations


Ads by Google