Ass 3
Ass 3
UNIT-3
◆Answer the following Question:
1) What are the major differences between doGet() and doPost()?
Explain with examples.
web.xml file
<web-app>
<servlet>
<servlet-name>sonoojaiswal</servlet-name>
<servlet-class>DemoServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sonoojaiswal</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>
Description of the elements of web.xml file
There are too many elements in the web.xml file. Here is the
illustration of some elements that is used in the above web.xml
file. The elements are as follows:
<web-app> represents the whole application.
<servlet> is sub element of <web-app> and represents the
servlet.
<servlet-name> is sub element of <servlet> represents the
name of the servlet.
<servlet-class> is sub element of <servlet> represents the class
of the servlet.
<servlet-mapping> is sub element of <web-app>. It is used to
map the servlet.
<url-pattern> is sub element of <servlet-mapping>. This pattern
is used at client side to invoke the servlet.
1. **ServletContext:**
ServletContext represents a servlet's view of the web application
within which the servlet is running. It's unique for each web
application and is used to communicate with the servlet container.
ServletContext is mainly used for sharing resources across different
parts of the web application.
```java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
2. **ServletConfig:**
ServletConfig represents the configuration of a specific servlet in a
web application. It's created by the web container for each servlet
and used to pass initialization information to the servlet. It allows the
servlet to access information such as initialization parameters.
```java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
1. Session Cookies:
- Session cookies are also known as transient cookies.
- They are stored temporarily in the user's browser memory
(RAM) during the user's visit to a website.
- Session cookies are often used to store temporary
information about the user's session, such as a session ID or
user authentication status.
- These cookies are automatically deleted when the user
closes their web browser or when the session expires (e.g., due
to inactivity).
- In Java web applications, you can create session cookies
using Java Servlets or frameworks like JavaServer Faces (JSF).
The `HttpSession` object is commonly used to manage session
data.
2. Persistent Cookies:
- Persistent cookies are also known as stored cookies or long-
term cookies.
- They are stored on the user's device even after the user
closes their web browser.
- Persistent cookies have an expiration date set by the server,
and they can persist for a specified duration, even across
multiple sessions and browser restarts.
- These cookies are often used to remember user
preferences, login credentials, or other user-specific data.
- In Java web applications, you can create persistent cookies
using the `javax.servlet.http.Cookie` class.