Sunday, July 21, 2013

JSP: What are implicit objects in JSP?

Implicit objects in JSP are the Java objects that the JSP Container makes available to developers in each page. These objects need not be declared or instantiated by the JSP author. They are automatically instantiated by the container and are accessed using standard variables; hence, they are called implicit objects.The implicit objects available in JSP are as follows:

The implicit objects are parsed by the container and inserted into the generated servlet code. They are available only within the jspService method and not in any declaration.

  • request
  • response
  • pageContext
  • session
  • application
  • out
  • config
  • page
  • exception

JSP: What is jspInit(), _jspService() and jspDestroy() methods?

jspInit()

The jspInit() method of the javax.servlet.jsp.JspPage interface is similar to the init() method of servlets. This method is invoked by the container only once when a JSP page is initialized. It can be overridden by a page author to initialize resources such as database and network connections, and to allow a JSP page to read persistent configuration data.

_jspService()

The _jspService() method of the javax.servlet.jsp.HttpJspPage interface is invoked every time a new request comes to a JSP page. This method takes the HttpServletRequest and HttpServletResponse objects as its arguments. A page author cannot override this method, as its implementation is provided by the container.

jspDestroy()

The jspDestroy() method of the javax.servlet.jsp.JspPage interface is invoked by the container when a JSP page is about to be destroyed. This method is similar to the destroy() method of servlets. It can be overridden by a page author to perform any cleanup operation such as closing a database connection.

JSP: What is the life-cycle of JSP?

When a request is mapped to a JSP page for the first time, it translates the JSP page into a servlet class and compiles the class. It is this servlet that services the client requests. A JSP page has seven phases in its life cycle, as listed below in the sequence of occurrence:

  • Translation
  • Compilation
  • Loading the class
  • Instantiating the class
  • jspInit() invocation
  • _jspService() invocation
  • jspDestroy() invocation

JSP: What are the advantages of JSP over Servlet?

JSP is a serverside technology to make content generation a simple appear. The advantage of JSP is that they are document-centric. 

Servlets, on the other hand, look and act like programs. 

A Java Server Page can contain Java program fragments that instantiate and execute Java classes, but these occur inside an HTML template file and are primarily used to generate dynamic content. Some of the JSP functionality can be achieved on the client, using JavaScript. The power of JSP is that it is server-based and provides a framework for Web application development.

Struts: What is MVS Architecture in Struts?

The model contains the business logic and interact with the persistence storage to store, retrieve and manipulate data.

The view is responsible for dispalying the results back to the user. In Struts the view layer is implemented using JSP.



The controller handles all the request from the user and selects the appropriate view to return. In Sruts the controller's job is done by the ActionServlet.


The following events happen when the Client browser issues an HTTP request.

  • The ActionServlet receives the request.
  • The struts-config.xml file contains the details regarding the Actions, ActionForms, ActionMappings and ActionForwards.
  • During the startup the ActionServelet reads the struts-config.xml file and creates a database of configuration objects. Later while processing the request the Action Servlet makes decision by refering to this object.
When the ActionServlet receives the request it does the following tasks.
  • Bundles all the request values into a JavaBean class which extends Struts Action Form class.
  • Decides which action class to invoke to process the request.
  • Validate the data entered by the user.
  • The action class process the request with the help of the model component. The model interacts with the database and process the request.
  • After completing the request processing the Action class returns an ActionForward to the controller.
  • Based on the ActionForward the controller will invoke the appropriate view.
  • The HTTP response is rendered back to the user by the view component.
 -----------------------------------------------------------------------------------------------------------------------------------------------------------
Good Day......
Amit Kumar Roy




Shell Script: Convert MS word file in ASCII Format

----------------------------------------------------------------------------------
script       :  mswordtotext 
purpose   :  display ms word doc file in ascii format 
requires   :  standard GNU commands, catdoc 
version    :  1.0
----------------------------------------------------------------------------------
usage      :  word2txt [-hl] <doc_file> [doc_file...] 
options    :  
     -h, usage and options (this help)

     -l, see this script"
----------------------------------------------------------------------------------
Enjoy:) Amit Kumar Roy
----------------------------------------------------------------------------------

Shell Script: Remove lines that contain words stored in a list

---------------------------------------------------------------------
script        :  remlines 
purpose    :  remove lines that contain words stored in a list 
requires    :  standard GNU commands 
version     :  1.0  

---------------------------------------------------------------------
usage:  rmlines [-hl] -i <word_list> -o <file> 
options:  
     -i, file with words to remove


     -o, file from which to remove the words


     -h, usage and options (this help)


     -l, see this script"

----------------------------------------------------------------------
Enjoy...Amit Kumar Roy
----------------------------------------------------------------------