JavaBeans and MVC in Jsp

JavaBean :


  • JavaBean is a class that follow the predefine specification such as….
  • Class have a no-argument(default) constructor.
  • Methods start either with set or get(means can only have setter and getter method).
  • Bean class must implement either serializable or externalizable interface.
  • Used to share information through out the web-application by creating instance of JavaBeans.
  • It can encapsulates many object by creating setter and getter of objects also.

POJO Class:


  • POJO i.e. Plane Old Java Object class very similar to JavaBeans it can have only setter and getter.
  • Java object that does not bound by any restriction/specification other than those forced by the Java Language
  • Java object which does not follow any of the major Java object models, conventions, or frameworks
  • Used for implementing the business logic.
  • All the JavaBeans are POJO but all POJO are may not be JavaBeans.

Jsp and JavaBeans:

Jsp provide some tags for implementation of JavaBeans .
These tags are known as action tag.
  1. <jsp:useBean/>
  2. <jsp:setProperty/>
  3. <jsp:getProperty/>

jsp:useBean :

This tag tells the container which bean class is going to be used , tells about scope and id represent the Javabeans.

Attribute of <jsp:useBean>

                                1)id
                                2)class
                                3)scope
                                4)type
                                5)beanName
Example:
<jsp:useBean id=“bean1” class=“bean.Employee” scope=“request” />

jsp:setProperty :

This tag is used to set the dispatched form value into the corresponding setter of JavaBeans.
Attribute of <jsp:setProperty/>……..
                                1)name
                                2)property
                                3)param
                                4)value
Condition to Use jsp:setProperty:
The value of ‘name’ attribute of < jsp:setProperty> is same as the value of ‘id’ attribute of <jsp:useBean> tag.
Name of dispatched field must be matched with the fields of JavaBeans otherwise cant set the values.
To set the value of all the setter ‘*’ is used as the value of property attribute, if  pass the ‘name’ of field as a value of ‘property’ attribute  then it only sets the value of corresponding setter..

jsp:getproperty :

It is the action tag of Jsp.
It is used to get the value from the JavaBeans .
Attributes of <jsp:getProperty>:
                                1)name
                                2)property
The value of ‘name’ attribute is same as the value of ‘id’ attribute  of <jsp:useBean> tag.
The value of ‘property’ attribute is same as the field which value of to get i.e. which getter have to call.

MVC i.e. MODEL VIEW CONTROLLER


  • Model: it represent the business logic and data on which programmer have to work.
  • View: it represent the presentation logic(view).
  • Controller: it represent the work of flow means handle all the request.
  • It is design pattern that is used for development of a web application. it give extra benefit to web-application.

Feature of MVC:


  • Separates the business logic, presentation logic and data within a web-application.
  • In this way it allow….
  • Reusability
  • Security
  • Independency
  • Simplicity
  • Maintainability
  • Easy to Test

Types Of MVC:

There is two types of MVC design Pattern….
                                1)MVC1(Model-1 Architecture)
                                2)MVC2(Model-2 Architecture)

Model-1 Architecture:

In this architecture client directly access the pages in the web container. And Application developer implement the presentation logic code and workflow code in the single page (JSP page) and data (JavaBeans/POJO) and business logic are in other.




Model-2 Architecture:

In this architecture client can not access the web container directly. First Client send the request then Controller process this request to server .Generally this component implement in Servlet and the controller component uses the model(JavaBean) then  process the request and display (use JSP page for view) it into  the client browser.
In MVC2 Servlet(controller)Play a Major role and make control centralized  whenever have to generate a view control  goes to Servlet.



*********************************************************************************
Reach us At: - 0120-4029000 / 24 / 25 / 27 / 29 Mobile: 9953584548
Write us at: - Smruti@apextgi.com and pratap@apextgi.com











No comments:

Post a Comment