Servlet’s Life…

Initializing… When the Web Container is started the container loads the servlet class and create the instance of  the servlet. The container calls the no-argument init() method (called only once) on the servlet instance after the servlet instance is created but before the servlet can service any request.   Servicing… 1. When a user clicks a ...

Servlet’s Life moment Listeners

Scenario  Listener interface  Event type  You want to know if an attribute in a web app context has been added, removed, or replaced. javax.servlet.ServletContextAttributeListener attributeAdded attributeRemoved attributeReplaced ServletContextAttributeEvent  You want to know how many concurrent users there are. In other words, you want to track the active sessions. (We cover sessions in detail in the ...

RequestProcessor Class

RequestProcessor Class is the actual place where the request processing takes place in a Struts controller environmentStruts Documentation When the request object first reaches the actionservlet class ,it invokes the process method of the underlying  RequestProcessor Class.   This process method then looks into the struts-config.xml file and tries to locate the name of the action that has come with ...

RequestDispatcher

A RequestDispatcher object can forward a client’s request to a resource or include the resource itself in the response back to the client. A resource can be another servlet, or an HTML file, or a JSP file, etc. You can also think of a RequestDispatcher object as a wrapper for the resource located at a given path ...

JSP include standard action and include directive

S.No.  include directive  JSP include <jsp:include page="..." ></jsp:include>..........  1. Content of the file specified in the attribute “file” of the include directive will be pasted as it is at tranlation time , where include directive is used in the jsp  At runtime, the includED file will be executed and the response will be included in the includING ...

Jsp Implicit Objects and EL implicit Variables

Jsp Implicit Objects  EL Implicit Variables  1. JspWriter out 2. HttpServletRequest request 3. HttpServletResponse response 4. HttpSession session 5. ServletContext application 6. Servlet config 7. Throwable exception 8. PageContext pageContext 9. Object page 1. cookie 2. pageContext 3. header 4. headerValues 5. param 6. paramValues 7. initParam 8. applicationScope 9. requestScope 10. sessionScope 11. pageScope

Invalid Statements

1. Using the method isUserInRole(), overrides any declarative authorization related to method in which it is invoked – isUserInRole() method itself doesn’t do any authorization. 2. name - value attribute is mandatory for  3. Benefits of the JSP precompilation is , it avoids initialization on the first request. 4.             java.lang.Error             /error.html           - valid value ...

forward and sendRedirect

Whenever there is a request from the client (or browser) to the server, the server container creates two objects 1. request 2. response and pass these objects to the servlet along with other parameters if needed.    S.No.  RequestDispatcher.forward  HttpServletResponse.sendRedirect  1. the request is forwarded to other resource(say B) in the same context, B does some ...

flushing buffer means?

Flushing means the data processed so far can go to the client even if the rest of the page isn’t done yet. It’s useful when you have a lot of data to send like in a download. flush=true : means send to client flush=false : means wait.

Attributes and Parameters in Servlets

   Attributes  Parameters  Types 1. Application/context 2. Request 3. Session  1. Application/context init parameters 2. Request parameters 3. Servlet init parameters  Method to set  setAttribute(String name, Object value)  You CANNOT set Application and Servlet init parameters—they’re set in the DD,  Return type  Object  String  Method to get  getAttribute(String name)  return type of the method is Object   getInitParameter(String name) ...