Showing posts with label JEE. Show all posts
Showing posts with label JEE. Show all posts

Wednesday, March 30, 2011

Java HttpServletResponse

HttpServletResponse is an interface from package javax.servlet.http. It extends javax.servlet.ServletResponse.

The important interface members are:
* addCookie(Cookie cookie);
* addHeader(String name, String value);
* sendError(int sc) Sends an error response to the client using the specified status code and clearing the buffer;
* sendError(int sc, String msg) Sends an error response to the client using the specified status.
* sendRedirect( String newLocation ) throws IOException - Sends a temporary redirect response to the client using the specified redirect location URL. Realised by http code 302 (Redirect).
* setHeader(String name, String value);
* setStatus(int sc) Sets the status code for this response.

Noticable methods from the super interface javax.servlet.ServletResponse:
* String getCharacterEncoding();
* String getContentType() - Returns the content type used for the MIME body;
* boolean isCommitted();
* setCharacterEncoding(String charset);
* setContentType(String type);

Tuesday, March 29, 2011

Java ServletContext

ServletContext is an interface from package javax.servlet;

Getting ServletContext
ServletContext could be get by session.getServletContext() method.
HttpSession could be get by request.getSession( boolean create );

The most important members are:
* addFilter(java.lang.String filterName, Filter filter) - Registers the given filter instance with this ServletContext under the given filterName;
* addListener(java.lang.Class listenerClass) - Adds a listener of the given class type to this ServletContext;
* Object getAttribute(java.lang.String name);
* ClassLoader getClassLoader();
* String getContextPath();
* getMimeType(java.lang.String file);
* log( String message, Throwable throwable );
* setAttribute( String name, java.lang.Object object );

Java HttpSession

HttpSession is interface from package javax.servlet.http.

Getting HttpSession
A HttpSession object could be get by request.getSession( boolean create );

The most important methods are:
* Object getAttribute(java.lang.String name);
* Enumeration getAttributeNames();
* long getCreationTime();
* long getLastAccessedTime();
* ServletContext getServletContext();
* invalidate();
* removeAttribute(java.lang.String name);
* setAttribute( String name, Object value );
* setMaxInactiveInterval(int interval) - Specifies the time, in seconds;
*

java HttpRequest

The interface HttpRequest is located in package javax.servlet.http.

Here are some important members:
* Cookie[] getCookies()
* String getHeader(java.lang.String name) - Returns the value of the specified request header as a String
* String getMethod() - GET, POST, or PUT
* String getQueryString() - Returns the query string that is contained in the request URL after the path.
* String getRemoteUser() - Returns the login of the user making this request, if the user has been authenticated;
* String getRequestURI() - Returns the part of this request's URL from the protocol name up to the query string;
* StringBuffer getRequestURL() - Reconstructs the URL the client used to make the request;
* HttpSession getSession( boolean create );
* boolean isUserInRole( String role );

----
And some inherited from javax.servlet.http.Request:
* Object getAttribute( String name );
* Enumeration getAttributeNames();
* String getContentType() - Returns the MIME type of the body of the request;
* String getParameter( String name );
* Enumeration getParameterNames();
* String getServerName();
* int getServerPort();
* String getRemoteHost() - Returns the fully qualified name of the client ( or the last proxy that sent the request);
* setAttribute( String name, Object o);
* removeAttribute(java.lang.String name);
* Locale getLocale();