Javaaa
Javaaa
Using Servlets, you can collect input from users through web
page forms, present records from a database or another source,
and create web pages dynamically.
Applications of Servlet
• Read the explicit data sent by the clients (browsers). This
includes an HTML form on a Web page or it could also come
from an applet or a custom HTTP client program.
• Read the implicit HTTP request data sent by the clients
(browsers). This includes cookies, media types and
compression schemes the browser understands, and so forth.
• Process the data and generate the results. This process may
require talking to a database, executing an RMI or CORBA
call, invoking a Web service, or computing the response
directly.
Servlets Architecture
The following diagram shows the position of Servlets in a Web
Application.
Servlets - Life Cycle
A servlet life cycle can be defined as the entire process from its
creation till the destruction. The following are the paths followed
by a servlet.
web.xml file
1. <web-app>
2.
3. <servlet>
4. <servlet-name>sonoojaiswal</servlet-name>
5. <servlet-class>DemoServlet</servlet-class>
6. </servlet>
7.
8. <servlet-mapping>
9. <servlet-name>sonoojaiswal</servlet-name>
10. <url-pattern>/welcome</url-pattern>
11. </servlet-mapping>
12.
13. </web-app>
Ex:- ArrayList
// Java program to demonstrate the
// working of ArrayList
import java.io.*;
import java.util.*;
class GFG {
// Main Method
// initial size n
al.add(i);
// Printing elements
System.out.println(al);
al.remove(3);
System.out.println(al);