Download presentation
Presentation is loading. Please wait.
Published byErin Rogers Modified over 9 years ago
2
1 CS6320 – Deployment and Context L. Grewe
3
2 The Servlet Container Servlets run in a container sometimes called the Servlet engine. Servlets run in a container sometimes called the Servlet engine. You must “deploy” a servlet for it to be able to run. You must “deploy” a servlet for it to be able to run. We deploy servlet(s) as part of a entity called a WebApp and this is what is actually deployed in our containers. We deploy servlet(s) as part of a entity called a WebApp and this is what is actually deployed in our containers. Many kinds of Servlet Containers available free and commercial Many kinds of Servlet Containers available free and commercial
4
3 Supporting Servlets To run Servlets, the Web server must support them To run Servlets, the Web server must support them Apache TomcatApache Tomcat Also functions as a module for other Apache servers Also functions as a module for other Apache servers Sun Java System Web Server and Java System Application Server (J2EE Server)Sun Java System Web Server and Java System Application Server (J2EE Server) IBM 's WebSphere Application ServerIBM 's WebSphere Application Server BEA ’s Weblogic Application ServerBEA ’s Weblogic Application Server Macromedia ’s Jrun – an engine that can be added to Microsoft’s IIS, Apache’s Web servers and more...Macromedia ’s Jrun – an engine that can be added to Microsoft’s IIS, Apache’s Web servers and more... Oracle Application ServerOracle Application Server …
5
4 For MORE DETAILS ON DEPLOYMENT and web.xml file see our class website!!!! THIS CAN CHANGE with your choice of servlet container!!! You will need a correct directory structure Compile your code Organize supporting files (html, etc) Create deployment descriptor files (e.g. container specific xml files like sun-web.xml for GlassFish and depending on version of J2EE optional web.xml file) Possibly zip up your code into a WebApp file called WAR (web archive). Finally, you need to deploy your Web Application (WebApp) using the containers administrative deployment tools. Deployment
6
5 … InitExample ServletInit login snoopy … Optional of the WebApp deployment descriptor file web.xml ---Servlet 3.* and on use container specfic xml + annotations in code –see webpage
7
6 Loading a Servlet on Startup A Servlet is usually loaded when it is first being called A Servlet is usually loaded when it is first being called You can set Tomcat to load a specific Servlet on startup in the Servlet declaration inside web.xml You can set Tomcat to load a specific Servlet on startup in the Servlet declaration inside web.xml InitExample ServletInit
8
7 The Servlet Context
9
8 The Servlet Context Object A Servlet context represents the Web application that Servlets live in A Servlet context represents the Web application that Servlets live in There is one Servlet context per application There is one Servlet context per application You can get the Servlet context using the method getServletContext() You can get the Servlet context using the method getServletContext() The Servlet context has many methods The Servlet context has many methods For example, you can store in it objects that are kept throughout the application's life For example, you can store in it objects that are kept throughout the application's life
10
9 An Example: Service Count public class CounterServlet extends HttpServlet { public void init() throws ServletException { Integer counter = (Integer)getServletContext().getAttribute("counter"); if(counter == null) { getServletContext().setAttribute("counter",new Integer(0)); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.