1 / 19

How CGI and Java Servlets are Run

How CGI and Java Servlets are Run. By David Stein 14 November 2006. CGI. 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. What is needed in order to create and run a CGI program?.

mohawk
Télécharger la présentation

How CGI and Java Servlets are Run

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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: • Internet access • Web browser • 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? • User requests a web page • Web server responds with request • User enters data into an HTML form and sends it back to the web server • HTML form (Get or Post) • Server receives the request from the user and processes the form • Compiled or Interpreted • Server responds with appropriate data to the user

  7. CGI Process HTTP Request Internet 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 • <html> • <head> • <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> • <title>Your Feedback</title> • </head> • <body> • <?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. <br />"; • print "You stated that you found this example to be $response and added: $comments"; • ?> • </body> • </html>

  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 HTTP Response Internet Java VM (servlet engine) HTTP Request Developer with JSDK 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("<HTML><HEAD><TITLE>Hello Client!</TITLE>"+ "</HEAD><BODY>Hello Client!</BODY></HTML>"); • 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. Sources • PHP (Visual Quick Start Guide) • By Larry Ullman • http://www.novocode.com/doc/servlet-essentials • http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html • http://java.sun.com/products/servlet/whitepaper.html

More Related