Skip to main content

Directive Tags

Directive tags
-->These tags gives direction to jsp page compiler towards generating code in JES class
Syntax
  1. <%@ Directive tag attribute %>
-->The three directive tags:-
1.)Page directive
-->To provide various inputa to jsp page like buffersize, contentType and etc..)
2.)Include directive
-->To include content of a file to jsp page
3.)Tag lib directive
-->To use Taglib libraries (it is library that contains set of jsp tags)
(1)Page Directive
Standard syntax
  1. <%@page attributes %>
Xml syntax
  1. <jsp:directive.page attributes %>
Attributes
Import, info, contentType, buffer, autoFlush, session, extends, isELIgnored, isThreadSafe, errorPage, isErrorPage and etc...
1.)Import
-->Useful to import packages in JES class
-->Use these attribute to import other than servlet-api, jsp-api related packages
-->We can specify these attribute for multiple times either in same <%@page%> tag or multiple <%@page%>tag
  1. E.g:
  2. <%@page import="java.sql.*, java.net.*"%>
  3. E.g:
  4. <%@page import="java.sql.*, java.util.*"%>
  5. E.g:
  6. <%@page import="java.sql.*"%>
  7. <%@page import="java.net.*"%>
2.)contentType
-->Given to specify MIME type as the response content type for jsp. It internally calls res.setContentType(-) method in JES class
E.g:
  1. <%@page contentType="text/xml"%>
Note: The default value of this attribute is "text/html"
-->If we call <%response.setContentType(-)%> explicitly then the contentType specified here will be taken as the final response content type for jsp
3.)Info
-->Useful to write short description about jsp page
-->Useful to know purpose of jsp page by seeing header section of the jsp page, internally overrides'  getServletInfo() method having this short description
test.jsp
  1. <%@page info="test jsp page"%>
In JES class
  1. publi class test_jsp extends..{
  2. public String getServletInfo(){
  3. return "test jsp page"
  4. }
  5. }
4.)Session
-->Specifies whether the implicit object session should be created or not
  1. <%@page session="false"%>
-->The implicit object session will not be created
  1. <%@page session="true"%>
-->The implicit object session will be created
-->Generally we need session object only in session tracking otherwise session object need is optional in jsp
5.)extends
-->Allows to specify super class for JES class to get some control on JES class execution. This class must extends from HttpServlet and must implement from HttpJspPage(I) having servlet life cycle methods internally calling jsp life cycle methods
-->Developing these class is very complex, so these is not a recommended attribute to use
  1. <%@page extends="TestBase"%>
JES class
  1. public class first_jsp extends TestBase{
  2. ...
  3. }
Note: It is recommended to use container supplied java class as the super class of JES class
6.)buffer
-->Buffer is temporary memory that holds data for temporary period
-->servlet component writes it's output directly to response object without buffer whereas jsp component takes the support of buffer whose default size is 8kb as shown below
-->The content return to buffer will be flushed to response object when buffer is fully filled up or when it is flushed out explicitly or execution of the code placed in jsp is completed

-->Allows to specify the above discussed jsp buffer size, even useful to disabled buffer, default size is 8kb
E.g
  1. <%@page buffer="10kb"%>
  2. -->Enables 10kb buffer
  3. <%@page buffer="none"%>
  4. -->Disables the buffer(jsp component directly qrites the output to response object)
7.)autoflush
-->The process of sending buffer content to it's real destination (response obj) is called flushing. Jsp component /container automatically flushes the content of buffer once buffer is filled up or when jsp execution is completed because the default value of autoFlush attribute is true
E.g:
  1. <%@page buffer="10kb" autoFlush="true"%>
E.g:
  1. <%@page buffer="none" autoFlush="false"%>
  2. -->Gives badCombo Error (we can't disable autoflush when buffer is not there)
E.g:
  1. <%@page buffer="1kb" autoFlush="false"%>
  2. <% for (int i=1;i<=1000;i++){
  3.    out.println("tej"+i);
  4. }
  5. %>
Raises IOException Error: JSP Buffer overflow
Solution
Either enable autoFlush="true" or explicitly call out.flush(-) inside the for loop
E.g:
  1. <%@page buffer="1kb" autoFlush="false"%>
  2. <% for (int i=1;i<=1000;i++){
  3.     out.flush();
  4.    out.println("tej"+i);
  5. }
  6. %>

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...

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(-...

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 ...