Chapter 06 Servlet
Chapter 06 Servlet
<param-name>dname </param-name>
<param-value> sun.jdbc.odbc.JdbcOdbcDriver
</param-value>
</context-param>
HttpServl
et
It extends GenericServlet class and
implements Servlet, ServletConfig and
Serializable interface.
It provides http specific methods such as
doGet, doPost, doHead, doTrace etc.
HttpServlet
Create two servlet file, one will save user name into
session and that session information is send to another
servlet. This example shows the session tracking.
RequestDispatc
her
The RequestDispatcher class enables your servlet to "call"
another servlet from inside another servlet.
We can obtain a RequestDispatcher from the
HttpServletRequest object.
Example:
Persistent cookie:
It is valid for multiple session . It is not removed each time
when user closes the browser. It is removed only if user
logout or sign-out or clear cookies/cache memory of
browsers.
Cookie:
Pros/Cons
Advantages:
Simplest technique of maintaining the state.
Cookies are maintained at client side.
Disadvantages
It will not work if cookie is disabled from the browser.
Only textual information can be set in Cookie object.
Cookie:
Constructor
javax.servlet.http.Cookie class provides the
functionality of using cookies. It provides a lot of
useful methods for cookies.
Constructor Description
Cookie() constructs a cookie.
Cookie(String name, String value) constructs a cookie with a specified
name and value.
Cookie:
Methods
Useful
methods:
Method Description
public void setMaxAge(int expiry) Sets the maximum age of the cookie in
seconds.