Java Servlet Ziad A AlSharif Overview Servlet technology

  • Slides: 8
Download presentation
Java Servlet Ziad A. Al-Sharif

Java Servlet Ziad A. Al-Sharif

Overview • Servlet technology is used to create web application that • resides at

Overview • Servlet technology is used to create web application that • resides at the server side and • generates dynamic web page • Before Servlet, CGI (Common Gateway Interface) scripting language was popular as a server-side programming language. • What is a Servlet? • • A technology i. e. used to create web applications An API that provides many interfaces and classes An interface that must be implemented for creating any servlet A class that extend the capabilities of the servers and respond to the incoming request. • It can respond to any type of requests • A web component that is deployed on the server to create dynamic web page

Servlet

Servlet

Servlet vs. CGI A Servlet has: • Better performance: because it creates a thread

Servlet vs. CGI A Servlet has: • Better performance: because it creates a thread for each request not process. • Portability: because it uses java language. • Robustness: because it is managed by the JVM, thus we don't need to worry about memory leak, garbage collection etc.

Static vs. Dynamic Websites Static Website Dynamic Website • Prebuilt content is same every

Static vs. Dynamic Websites Static Website Dynamic Website • Prebuilt content is same every time the • Content is generated quickly and page is loaded. changes regularly. • It uses the HTML code for developing • It uses the server side languages such a website. as: PHP, SERVLET, JSP, and ASP. NET etc. for development • It sends exactly the same response for • It may generate different HTML for every request. each of the request. • The content is only changes when • The page contains "server-side" code someone publishes and updates the file that allows the server to generate the (sends it to the web server). unique content when the page is loaded. • Flexibility is the main advantage of • Content Management System (CMS) static website. is the main advantage of dynamic website.

Servlet Container • It is the part of web server which can be run

Servlet Container • It is the part of web server which can be run in a separate process. We can classify the servlet container states in three types: 1. Standalone: It is typical Java-based servers in which the servlet container and the web servers are the integral part of a single program. For example: - Tomcat running by itself 2. In-process: It is separated from the web server, because a different program runs within the address space of the main server as a plug-in. For example: - Tomcat running inside the JBoss. 3. Out-of-process: The web server and servlet container are different programs which are run in a different process. For performing the communications between them, web server uses the plug-in provided by the servlet container.

Servlet Container • It is the part of web server which can be run

Servlet Container • It is the part of web server which can be run in a separate process. We can classify the servlet container states in three types: Servlet Container performs many operations that are given below: 1. Life Cycle Management 2. Multithreaded support 3. Object Pooling 4. Security etc.

Example 1: JSP scriptlet tag index. html <html> <body> <form action="welcome. jsp“ > <input

Example 1: JSP scriptlet tag index. html <html> <body> <form action="welcome. jsp“ > <input type ="text" name="uname“ > <input type ="submit" value="go"> </form> </body> </html> welcome. jsp <html> <body> <% String name = request. get. Parameter("uname"); out. print("welcome : “ + name ); %> </body> </html>