MVC1 VS MVC2

    MVC is a design pattern. It contains two models:-
    1)MVC Model 1
    2) MVC Model 2
MVC1 MVC2
HTML or JSP files are used to code the presentation. JSP files use java beans to retrieve data if required. This architecture removes the page-centric property of MVC1 architecture by separating Presentation, Control logic and Application state.
MVC1 architecture is page-centric design all the business and processing logic means any JSP page can either present in the JSP or may be called directly from the JSP page. In MVC2 architecture there is one Controller which receive all request for the application and is responsible for taking appropriate action in response to each request.
MVC1 both view and controller implemented in servlets . MVC2 view implemented in JSP and controller implemented in servlets.

EL

  • EL Stands for Expression Language.

  • EL was added to the JSP 2.0 and introduced in JSTL 1.0.

  • EL expression always in the curly braces,and prefixed with the dollar sign.
  • Expression Language use for JSP applications,to simplify the maintenance by avoiding scripting elements.

Syntax:-
       {firstThing.secondThing}
Example:-${person.name}

In Above Example,

firstThing shows EL Implicit Object such as-pageScope, requestScope, sessionScope, applicationScope, param, paramValues, header, headerValues, cookie, initParam, pageContext Or Map, Bean, List.

secondThing:-Property,Index,Key
Example:-
${person.name} or ${person["name"]
String [] names= {"Amit", "Shyam", "Ram"};
Request.setAttribute("namesList",names);
${nameList} // Will print entire name list
${nameList[0]} or${nameList["0"]}

EL Implicit Objects:-
Implicit Object Example Remark
param ${param.name} request.getParameter ("name");
paramValues ${paramValues.hobbies[0]} request.getParameterValues ("hobbies")[0];
header ${header["host"] request.getHeader ("host");
request ${request.method} // through this object you can get the request properties request.getMethod();
requestScope ${requestScope.phones[0]} //requestScope is used for set and get attribute it is not an request object request.getAttribute ("phones");
cookie ${cookie.userName.value} cookie[i].getValue();
initParam ${initParam.mainEmail} config.getInitParameter ("mainEmail");
sessionScope ${sessionScope.phones[0]); session.getAttribute ("phones");

JSTL

  • JSTL stands for JavaServer Pages Standard Tab Library.

  • It is introduced in JSTL 1.2.

  • It is a set of Java tag libraries that use for simplify coding on JSP.

  • JSTL includes a wide variety of tags that fit into seperate functional areas.

  • Libraries are as follows:-
    Core:- http://java.sun.com/jsp/jstl/core

    XML:- http://java.sun.com/jsp/jstl/xml

    Internationalization:- http://java.sun.com/jsp/jstl/fmt

    SQL:- http://java.sun.com/jsp/jstl/sql

    Functions:- http://java.sun.com/jsp/jstl/functions

  • You have required to download two jar files, jstl.jar and standard.jar from the JSTL jars at http://jakarta.apache.org/site/downloads /downloads_taglibs-standard.cgi.

  • Add jstl.jar and standard.jar to the WEB-INF/lib directory of your web application project.

  • When You want to create a jsp :-
    You need to specify which JSTL 1.0 core library tags used,which can be declared on your jsp as follows:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>

Classic Tag

  • A classic tag is a Java class.

  • It implements the Tag,IterationTag, or BodyTag interface.

  • It is the runtime representation of a custom action
  • Tag interface, javax.servlet.jsp.tagext.Tag, was the top-level interface untill JSP 1.2 and other interfaces were sub-interfaces of the Tag interface.
  • However,JSP 2.0 is new top-level interface, javax.servlet.jsp.tagext.JspTag, has been introduced.
  • The Tag and SimpleTag interfaces both extend JspTag.
  • Tag interface:-
    • Tag interface is the base interface for all classic tag.
    • All classic tag handlers directly or indirectly implement Tag interface.
    • Tag interface used for writing basic tags that don't involve any iterations or processing of the tag's body content.
    Methods Description
    void setPageContext(PageContext) Calls this method to set the context for current page by Container.
    void setParent(Tag) Sets the parent tag,by Container.
    int doStartTag() Invokes this method on encountering the start of the tag by Container.
    int doEndTag() Invokes this method on encountering the end of the tag by Container.
    Tag getParent() Gets the parent of the current tag by this method.
    void release() Calls to release any resources held.
    Iteration interface:-
    • IterationTag interface used primarywhich the tag content is to be repeatedly generated.
    • IterationTag interface extends the Tag interface and provide single new method to enable reevaluation of the body of the tag.
    Methods Description
    Int doAfterBody() Calls after the body contents of the tag are evaluated by this method.
    BodyTag interface:-
    • The BodyTag interface extends the IterationTag interface.
    • It introduces two new methods and one new constant.
    • The purpose of this interface is enable buffering of the body content of a tag.
Methods Description
void setBodyContent(BodyContent) Calls this method just before calling doInitBodyand this method is called only if the tag has a body by Container.
void doInitBody () Calls this method just before body-tag processing begins by Container.
IterationTag and BodyTag,both interfaces are closely related,and BodyTag providing a content buffering capability that builds on the IterationTag capability, IterationTag does not provide. Use BodyTag to solve the problem that we face when using IterationTag.