Skip to main content

Implicit Objects

Implicit objects /Implicit reference variable:-
-->Technically speaking we should call them as implicit reference variables because these are local variables in _jspService(-,-) method pointing to the container created objects like request, response, ServletConfig, ServletContext and etc... objects
Implicit objects:-
(1)request
(2)response
(3)config
(4)application
(5)page
(6)PageContext
(7)session
(8)out
(9)exception
Reference type
(1)javax.servlet.HttpServletRequest(I)
(2)javax.servlet.HttpServletResponse(I)
(3)javax.servlet.ServletConfig(I)
(4)javax.servlet.ServletContext(I)
(5)java.lang.Object(c)
(6)javax.servlet.http.tagext.PageContext(AC)
(7)javax.servlet.http.HttpSession(I)
(8)javax.servlet.jsp.JspWriter(AC)
(9)java.lang.Throwable(c)
Scopes
(1)request
(2)request /response
(3)page
(4)application scope
(5)page scope
(6)page
(7)session
(8)page
(9)page
-->The above given reference types are not class names of implicit object there are ordinary interfaces and abstract class and top most hierarchy classes pointing to the container supplied object

Page scope: Data is specific to each jsp pages
Request scope: Data is visible through out request
Session scope: Data is specific to one browser software
Application scope: Data is visible in the entire web application irrespective of any connections
-->The implicit objects of jsp are the objects of underlying ServletContainer, JspContainer supplied java classes implementing the above given interfaces or extending from the above given class or abstract class
-->"out" is not the object of "JspWriter(AC)" , it is the object of underlying ServletContainer/ JspContainer supplied java class that extends from JspWriter(AC). In Tomcat server this class name is "JspWriterImpl" (look in jasper jar file)
E.g
  1.  out object class name:<%=out.getClass()>
-->We generally feel exception handling in jsp is optional, but it is only for the code that goes to _jspService(-,-) method(scriptlet code and expression tag code). The code that goes outside of _jspService(-,-) method like declaration tag code we must explicitly catch and handle the exception
-->All implicit object /reference variable or local variables in _jspService(-,-). So they can't be used in declaration tag because, the code placed in declaration tag go outside of _jspService(-,-) in JES class, but we can access some implicit object by creating separate reference variable by using servlet-api in declaration tags
-->ServletConfig object is container created object on one per servlet/ JES class object either during server startup or during the deployment of web application "config" is the implicit reference variable in _jspService(-,-) pointing to ServletConfig object but it can't be used in declaration class because it is local variable to _jspService(-,-), so we can write servlet-api code in declaration tag to get another reference variable pointing to ServletConfig object
  1. <%! public void jspInit()
  2.  {
  3.  ServletConfig cg=getServletConfig();
  4.  }
  5. %>
-->One object can have multiple references, if the implicit reference variable given by jsp is not visible then we can create some explicit reference variable for the same objects
-->We need ServletConfig object in jspInit() and also in other parts of jsp to read init() parameter values of jsp that are specified in web.xml file
In test.jsp
  1. public void jspInit()
  2. {
  3.  ServletConfig cg=getServletConfig();
  4. System.out.println("DB user init parameter value" + cg.getInitParameter("db user")
  5. }
In web.xml
  1. <servlet>
  2.    <servlet-name>test</servlet-name>
  3.    <jsp-file>/test.jsp</jsp-file>
  4.    <init-params>
  5.       <param-name>dbuser</param-name>
  6.       <param-value>scott</param-value>
  7.    </init-param>
  8. </servlet>
  9. <servlet-mapping>
  10.    <servlet-name>test</servlet-name>
  11.    <url-pattern>/testurl</url-pattern>
  12. </servlet-mapping>
URL:
http://localhost:1025/JspApp2/testurl
Note: The configurations done in web.xml for jsp will be applied only when jsp is requested with url pattern

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