Action Tags

Standard Action tags
-->Action tags are given to use servlet-api functionalities dynamically at runtime/execution phase of jsp page
-->Action tags will have only xml syntax to utilize. The tags are <jsp:forward>, <jsp:include> and etc...
Action include/<jsp:include>
-->Performs the output inclusion of destination jsp component to the source jsp components output
-->It internally uses rd.include(-,-) of servlet for including the output
-->Destination component executes separately and only its output will be included to the source jsp component
Syntax
  1. <jsp:include page="..." flush="true/false">
Page:-To specify destination jsp page
flush:-To enable /disable flushing while including destination page output to the buffer of source jsp page


A.jsp
  1. <b>from A.jsp</b>
  2. <jsp:include page="B.jsp" flush="true"/>
  3. <br>
  4. <p>End of A.jsp</p>
B.jsp
  1. <b>from B.jsp</b>
  2. <%=new java.util.Date()%>
  3. <br>end
(Q)What is the difference between directive include & action include?
Directive include
-->Performs code inclusion of destination component to the source JES class
-->Performs code inclusion at translation phase, so it is called compile time binding or static binding
-->Doesn't use rd.include internally
-->Doesn't generate JES class if destination component is jsp
-->Doesn't allow servlet component as destination component
-->Gives both standard , xml syntaxes
-->Useful if destination component is static component (html)
Action include
-->Performs output inclusion of destination component to the source JES class
-->Performs output inclusion at execution phase, so it is called dynamic binding or runtime binding
-->Uses rd.include
-->Generates JES class
-->Allows servlet component
-->Gives only xml syntax
-->Useful if the destination component is dynamic component (servlet/jsp)


-->All web pages of the web site maintained same header, footer contents, so instead of writing same header, footer logics in multiple components of web application, it is recommended to write in separate web components and include their output in main web components using include tags as shown above

-->In one jsp we can place multiple directive includes and action includes


Example app on both directive and action includes
JspApp8-BothIncludes
|-->java resources
      |-->src
           |-->org.servlet
                 |-->HeaderServlet.java
|-->webcontent
      |-->footer.jsp
      |-->news.jsp
      |-->sports.jsp
      |-->welcome.jsp
      |-->menu.jsp
      |-->page1.jsp
      |-->page2.jsp
      |-->page3.jsp
      |-->page4.jsp
<jsp:forward>
-->It is given to forward the request from source jsp page to destination web component by using rd.forward(-,-) internally, discard the entire output source jsp page and sends only the output of destination component to browser through source jsp page


Syntax
  1. <jsp:forward page="..."/>
Note: There is no directive forward tag only action forward tag is given
JspApp9-Forward
A.jsp
  1. <b>from A.jsp</b>
  2. <jsp:include page="B.jsp"/>
  3. <br>
  4. <b>A.jsp(end)</b>
B.jsp
  1. <b>from B.jsp</b>
  2. <%=new java.util.Date()%>
  3. End of B.jsp
-->In servlet programming the statements placed after rd.forward(-,-) in source servlet component will be executed but there output will be discarded

-->In jsp programming the statements placed after <jsp:forward> tag will not be executed because in JES class return will be placed after calling rd.forward(-,-) as shown in the above diagram

JSP Communication:
-->Talks about how the source jsp component interacts with destination web component. This can be done in multiple ways
a.)Forwarding request (<jsp:forward>)
-->When destination component is local to source jsp components
b.)Including response(<jsp:include>)
c.)Send redirection
-->When destination component is remote to source jsp component
-->While using a, b options the source jsp component and destination web component will use same request, response objects, while using c option this will not take place
<jsp:param>
-->Passes additional request param to destination component from source jsp, when source jsp interacts with destination component using <jsp:forward>, <jsp:include> tags
Syn:
  1. <jsp:param name="..." value="..."/>
-->Generally used as the sub tags of <jsp:forward>,<jsp:include> tags
In A.jsp
  1. <jsp:forward page="B.jsp">
  2. <jsp:param name="bkname" value="CRJ"/>
  3. </jsp:forward>
In B.jsp
  1. Additional request param value:
  2. <%=request.getParameter("bknqme")%>


-->bill.jsp uses <jsp:forward> tag to pass bill amount from bill.jsp to discount.jsp
JspApp10-ForwardUseCase
|-->webcontent
      |-->bill.jsp
      |-->discount.jsp
      |-->form.html
(Q)There is directive include tag, but why there is no directive forward tag ?
-->Any forward tag discards the output of source page, directive tags performs their operations at translation phase by including the code of destination component to JES class code of spurce jsp page due to this discarding the output of source jsp becomes practically impossible, for these no directive forward tag is given
Limitations of <jsp:forward> & <jsp:include> tags
-->Source jsp and destination web component must be there in same web application
-->Destination component can't be developed as php, asp.net component
-->To overcome these problems use  send redirection (response.sendRedirect(-) method)
Understanding res.sendRedirect(-) method:



-->In sendRedirection source component talks with destination component after having 1 network round trip with browser so the destination component can be there in remote location and can be there in any technology

Comments

Popular posts from this blog

Java Mail API

JSP Life Cycle

Project Architecture's