- With help of classes and interfaces available in this package, developing servlets made easy
Interfaces of javax.servlet.http package
|
|
HttpServletRequest
|
We read client request data.
|
HttpServletResponse
|
We write back client response.
|
HttpSessionBinding
|
Session level data.
|
HttpSessionBindingListener
|
To link/unlink a object to current session
|
Classes of javax.servlet.http package
|
|
HttpServlet
|
Provides methods for HTTP Request and Response.
|
HttpSessionEvent
|
Provides session-changeable events.
|
HttpSessionBindingEvent
|
Checks if session attribute changed/not.
|
Cookie
|
Allows to store information at client
side.
|
- HttpServletRequest Interface: As name indicates and explained earlier, this interface provides methods to read/get the client data from HTTP Request
Method of HttpServletRequest Interface
|
|
String getRequestedSessionId()
|
Provides ID of session
|
String getRequestURI()
|
Provides URI
|
StringBuffer getRequestURL()
|
Provides URL
|
String getServletPath()
|
Provides URL that identifies the
Servlet
|
HttpSession getSession()
|
Returns Session (If not created, new
session will be created)
|
boolean isRequestedSessionIdFromCookie()
|
Returns true if session ID is available
in cookie
|
boolean isRequestedSessionIdFromURL()
|
Returns true if session ID is available
in URL
|
boolean isRequestedSessionIdValid()
|
Returns true if current context
contains session id.
|
String getMethod()
|
Provides HTTP Method of request
|
- HttpServletResponse Interface: As name indicates and explained earlier, this interface provides methods to write data to client as HTTP Response
Methods of HttpServletResponse Interface
|
|
void sendRedirect(String newUrl)
throws I0Exception
|
Redirect the client to provided newUrl.
|
void sendError(int
errorcode) throws I0Exception
|
Sends error code to client.
|
void setStatus(int code)
|
Sets status code of this response to code
|
void addCookie(Cookie cookie)
|
Adds cookie to the HTTP response
|
void setHeader(String field, String value)
|
Adds relevant field to respective value
to Header
|
void setIntHeader(String field, int value)
|
Adds relevant field to respective value
to Header
|
String encodeURL(String url)
|
Decides whether session ID can be
encoded in respective url. If
available, returns modified url
|
- HtttpSession Interface: Provides methods to read and write the information related to state of HTTP Session
Methods of HttpSession Interface
|
|
boolean isNew( )
|
Returns true if session is not yet accessed by client
|
void
removeAttribute(String attr)
|
Removes specified attribute from session.
|
void setAttribute(String attr, Object val)
|
Adds new attribute to session with relevant value.
|
String getId( )
|
Returns Session Id.
|
Enumeration getAttributeNames( )
|
Returns an Enum with all list of
Attributes
|
Object getAttribute(String attr)
|
For given attribute, returns its value
in session.
|
long getCreationTime( )
|
Returns times since session is created (in milliseconds)
|
- HttpSessionBindingListener Interface: This need to implemented by a objects that need to be send a word when they are bound or unbound from HTTP Session
Methods of HttpSessionBindingListener
Interface
|
|
void
valueBound(HttpSessionBindingEvent e)
|
To bound with event e that describes binding.
|
void valueUnbound(HttpSessionBindingEvent e)
|
To unbound with event e that describes binding.
|