高级Web技术 Java 2 Enterprise Edition
高级Web技术 Java 2 Enterprise Edition
本次课程内容 Servlet and jsP overview Introduction to Servlets Request Response Session Tracking Introduction to JavaServer Pages
本次课程内容 ◼ Servlet and JSP Overview ◼ Introduction to Servlets ◼ Request ◼ Response ◼ Session Tracking ◼ Introduction to JavaServer Pages
Servlet and JsP Overview
Servlet and JSP Overview
J2EE Architecture An extensible Web technology that uses template data. Java Servlet A Java program that custom elements, scripting languages, and server-side extends the functionality of a Web Java objects to return dy namic content to a client server, generating dynamic content ypically the temp late data is HTML or XML elements. and interacting with Web clients Ty The client is often a web browser using a request-response paradigm Tools Application Programming Model Transactions Container Messaging Mail Java 2 SDK, Standard Edition CORBA RMI Database Naming/Directory
J2EE Architecture
Where is servlet and jsp Client-Side erver-Side Server-Side terprise resentation resentation Business Logic rmation Web EJB ystem Browser Container EJB Java JSP E DesKtoP Java Applicntion Servlet EJB other Device J2EE Platform Platform client Web Tier EJB Tier
Where is Servlet and JSP
Servlet definition Servlets are modules of Java code that run in a server application (hence the name Servlets", similar to Applets"on the client side to answer client requests. It is based on servlet APl and extendthefunctionalityofahttpserver. Servlets are not tied to a specific client-server protocol but they are most commonly used with Http and the word servlet"is oftenusedinthemeaningofhttpservlet Mapped to URLs and managed by container with a simple architecture Available and running on all major web servers and app servers Platform and server independent
Servlet Definition ◼ Servlets are modules of Java code that run in a server application (hence the name "Servlets", similar to "Applets” on the client side) to answer client requests. It is based on servlet API and extend the functionality of a HTTP server. ◼ Servlets are not tied to a specific client-server protocol but they are most commonly used with HTTP and the word "Servlet" is often used in the meaning of "HTTP Servlet". ◼ Mapped to URLs and managed by container with a simple architecture ◼ Available and running on all major web servers and app servers ◼ Platform and server independent
Servlet sample code PublicclasshelloservletextendshttpServlet publicvoiddoGet(httpServletrequestrequest Http servletrEsponse response response. setContentType( text/html") PrintWriter out response getWriter0 out println ( Hello World )
Servlet Sample Code
CGI and servlet CGI (Common Gateway Interface) Written in cc++, visual Basic and perl A CGi program and probably also an extensive runtime system or interpreter) needs to be loaded and started for each CGI request
CGI and Servlet ◼ CGI (Common Gateway Interface) ◼ Written in C, C++, Visual Basic and Perl ◼ A CGI program (and probably also an extensive runtime system or interpreter) needs to be loaded and started for each CGI request
CGI and servlet Servlets written in java A Servlet does not run in a separate process. This removes the overhead of creating a new process for each request. There is only a single instance which answers all requests concurrently. this saves memory and allows a servlet to easily manage persistent data. A servlet can be run by a servlet engine in a restrictive Sandbox Gust like an applet runs in a Web browser's Sandbox which allows secure use of untrusted and potentially harmful Servlets
CGI and Servlet ◼ Servlets ◼ Written in Java. ◼ A Servlet does not run in a separate process. This removes the overhead of creating a new process for each request. ◼ There is only a single instance which answers all requests concurrently. This saves memory and allows a Servlet to easily manage persistent data. ◼ A Servlet can be run by a Servlet Engine in a restrictive Sandbox (just like an Applet runs in a Web Browser's Sandbox) which allows secure use of untrusted and potentially harmful Servlets
CGI and servlet Request cAll Child for CAll Request CG12 CGI Based Child for cg12 Webserver Request cgIl Child for CAll Request Servlet Servlet Based Webserver Request servlet Servlet Request Servlet Servlet
CGI and Servlet