Skip to main content

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

JSP Comments

Comments in JSP:- -->Compiler /Interpreter doesn't take commented code for compilation /Interpretation, so the commented code doesn't participate in execution JSP supports 3 types of comments:- a.)HTML comments /Template text comments/ Output comments Syn :- <!---text---> -->Recognized by html interpreter of browser b.)JSP comments /Hidden comments Syn :- <%--text--%> -->JSP page compiler recognize these comments c.)Java comments /Scripting comments Syn :- //-->For single line /*-- -----*/-->For multiple line -->Java compiler(java) recognize these comments -->In Eclipse IDE JES class for first.jsp comes in our(workspace)folder/.metadata/.plugins/.org eclipse Comments (1)JSP comment<%--%> (2)Java comment(// or /*--*/) (3)HTML comments(<!---> JES Source Code (1)No (2)Yes (3)Yes In JES compiled code (1)No (2)No (3)Yes In the code going to browser (1)No (2)No (3)Yes Output (1)No (2)No (3)No -->Jsp comments are not visible in any phase...

Project Architecture's

1.) Functional flow/ Architecture a.) Only for 6+/7+years b.) Explain the flow of process/business 2.) Technical Flow/Architecture a.) Upto 5+ years b.) Explain technologies /components that are involved in the project Servlet & JSP Project Architecture:- 1.)What is need of Business Deligate to convert VO class object to DTO class object ? a.) If Business Deligate is not there servlet component directly prepares DTO class object by receiving and translating form data and passes to service class, if service class excepts certain input in other format like numeric employee number as string employee number then we need to modify servlet component code i.e For the changes that happened in business tier service component we have to modify servlet component of presentation tier b.) If Business Deligate is taken then it gets original form data as VO class object having string inputs and converts VO class object to DTO class object to pass to service class c.) If service class excepts ...

Scripting Tags

JSP Tags/ Elements (1)Scriptlet     Standard syn:-         <%.........%>     xml syn:-        <jsp:scriptlet>...</jsp:scriptlet> Note: All scripting tags allows us to place script code(java code) 1.)The code placed in scriptlet go to _jspService(-,-) of JES class 2.)In a jsp page we can have zero or more scriptlets 3.)We place request processing logics in scriptlets 4.)Variables declared in scriptlets becomes the local variables in _jspService(-,-) of JES class in first.jsp In first.jsp: <% int a=10;  out.println("square:"+(a*a));%> In first_jsp.java(JES): public class first_jsp extends..{     public void _jspService(-,-){        int t=30;        out.println(“Square:”+(t*t));     }  } The code placed in scriptlet can use implicit objects of jsp because implicit objects and the code placed scriptlet goes to _jspService(-...