Skip to content

Commit 2085438

Browse files
authored
updated Basic-Servlets-Examples readme commit
1 parent f19e293 commit 2085438

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

Basic-Servlets-Examples/README.md

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
1+
## The servlet can be created by three ways:
2+
* By implementing Servlet interface,
3+
* By inheriting GenericServlet class, (or)
4+
* By inheriting HttpServlet class
15

2-
# Servlet Life Cycle
6+
### GenericServlet
7+
* Implements  Servlet, ServletConfig andSerializable interface.
8+
* It provides the implementaion of all the methods of these interfaces except the service method.
9+
* GenericServlet class can handle any type of request so it is protocol-independent.
310

4-
![Servlet Life Cycle](https://github.com/SuneetPatil/Java-Servlets/blob/master/Images/ServletLifeCycle.png)
11+
### HttpServlet
12+
* class extends the GenericServlet class and implements Serializable interface.
13+
* It provides http specific methods such as doGet, doPost, doHead, doTrace etc
514

6-
* If an instance of the servlet does not exist, the Web container loads the class.
7-
* Creates an instance of the servlet class.
8-
* Initializes the servlet instance by calling the init method.
9-
* Invokes the service method, passing a request and response object, For Http Servlet, Service method invokes doGet, doPost, etc. methods as appropriate, Override only doGet or doPost etc. method as needed.
10-
* Finalize the request by calling Destroy method.
15+
## Package and Deployment
16+
<p align="center">
17+
<img src="https://github.com/SuneetPatil/Java-Servlets/blob/master/Images/PackageandDeployment.png" alt="Package and Deployment">
18+
</p>
19+
20+
### Deployment Descriptor :
21+
* web.xml is the deployment descriptor for web applications.
22+
* Every web application module must have a single web.xml file in the folder root/WEB-INF
23+
24+
```
25+
<web-app>
26+
<servlet>
27+
<servlet-name>GenericServlet</servlet-name>
28+
<servlet-class>com.suneet.GenericServletExample</servlet-class>
29+
</servlet>
30+
<servlet-mapping>
31+
<servlet-name>GenericServlet</servlet-name>
32+
<url-pattern>/exampleservlet</url-pattern>
33+
</servlet-mapping>
34+
</web-app>
35+
36+
```

0 commit comments

Comments
 (0)