{
"iq":[{"id":"1",
"q":"Explain JSP and tell its uses.",
"answer":"JSP stands for Java Server Pages. It is a presentation layer technology independent of platform. It comes with SUN’s J2EE platforms. They are like HTML pages but with Java code pieces embedded in them. They are saved with a .jsp extension. They are compiled using JSP compiler in the background and generate a Servlet from the page. "
},
{"id":"2",
"q":"What is the requirement of a tag library? ",
"answer":"A collection of custom tags is called a Tag Library. Recurring tasks are handled more easily and reused across multiple applications to increase productivity. They are used by Web Application designers who focus on presentation rather than accessing database or other services. Some popular libraries are String tag library and Apache display tag library. "
},
{"id":"3",
"q":"Explain JSP Technology.",
"answer":"JSP is a standard extension of Java and is defined on top of Servlet extensions. Its goal is to simplify management and creation of dynamic web pages. It is platform-independent, secure, and it makes use of Java as a server side scripting language."
},
{"id":"4",
"q":"How does a servlet differ from the JSP?",
"answer":"The JSP and Servlets are both web components and functionally similar. In fact, a JSP gets transformed into the servlet at run-time. The main variation between the two is that JSPs are useful for operations that are HTML-intensive whereas the Servlets are best-suited for tasks that are Java-intensive. The below example can elaborate the difference clearly.\n\nExample: A web application which follows the MVC model separates the components into three groups.\n\nModel- Represents the modules that contain application data e.g. Java beans.\n\nViews- It is the part of the application that displays information. e.g. dynamically generated HTML, JSP handles this part very well.\n\nControllers- Its job is to work as a carrier between the model and the view. The controller places the user entered information into the model and forwards it to the next view. Servlets fulfill this purpose perfectly. "
},
{"id":"5",
"q":"What are the JSP lifecycle phases? ",
"answer":"Translation\nCompilation\nClass Loading\nInstantiation\nInitialization\nRequest Processing\nDestroy "
},
{"id":"6",
"q":"What are JSP lifecycle methods? ",
"answer":"The JSP container executes the jspInit() method the first time it initializes the JSP.Whenever the container receives a request, it invokes the _jspService() method, processes the request and generates a response.The container calls the jspDestroy() method for cleaning up the memory allocated for the JSP. "
},
{"id":"7",
"q":"Which of the JSP life cycle methods you can override?",
"answer":"You can’t override the _jspService() Method within a JSP page. However, there are two approaches you can take to override the jspInit() and jspDestroy() methods within the JSP page.\n\njspInit() Can be quite useful for reserving resources like DB connections, N/W connections, and so forth for the JSP page. It is deemed as a good programming practice to free any allocated resources in the jspDestroy() method."
},
{"id":"8",
"q":"Is it possible for one JSP to extend another java class if yes how?",
"answer":"Yes it is possible we can extends another JSP using this <%@ include page extends=\"classname\" %> it’s a perfectly correct because when JSP is converted to servlet its implements javax.servlet.jsp.HttpJspPage interface, so for jsp page its possible to extend another java class . This question can be tricky if you don’t know some basic fact J, though it's not advisable to write java code in jsp instead it's better to use expression language and tag library."
},
{"id":"9",
"q":"what are the implicit Object ",
"answer":"This is a fact based interview question what it checks is how much coding you do in JSP if you are doing it frequently you definitely know them. Implicit object is the object that is created by web container provides to a developer to access them in their program using JavaBeans and Servlets. These objects are called implicit objects because they are automatically instantiated.they are bydefault available in JSP page.They are request, response, pageContext, session, and application, out, config, page, and exception."
},
{"id":"10",
"q":"How can you pass information form one jsp to included jsp:",
"answer":"This JSP interview question is little tricky and fact based. Using < Jsp: param> tag we can pass parameter from main jsp to included jsp page\n\nExample:\n<jsp:include page=\"newbid.jsp\" flush=\"true\">\n<jsp:param name=\"price\" value=\"123.7\"/>\n<jsp:param name=\"quantity\" value=\"4\"/>"
},
{"id":"11",
"q":"what is the need of tag library?",
"answer":"Ans tag library is a collection of custom tags. Custom actions helps recurring tasks will be handled more easily they can be reused across more than one application and increase productivity. JSP tag libraries are used by Web application designers who can focus on presentation issues rather than being concerned with how to access databases and other enterprise services. Some of the popular tag libraries are Apache display tag library and String tag library."
},
{"id":"12",
"q":"What are JSP directives?",
"answer":"JSP directives are messages for the JSP engine. i.e., JSP directives serve as a message from a JSP page to the JSP container and control the processing of the entire pageThey are used to set global values such as a class declaration, method implementation, output content type, etc.They do not produce any output to the client.\nDirectives are always enclosed within <%@ ….. %> tag.\n\nEx: page directive, include directive, etc."
},
{"id":"13",
"q":"What are implicit objects in JSP?",
"answer":"Implicit objects in JSP are the Java objects that the JSP Container makes available to developers in each page. These objects need not be declared or instantiated by the JSP author. They are automatically instantiated by the container and are accessed using standard variables; hence, they are called implicit objects.The implicit objects available in JSP are as follows:\nrequest\nresponse\npageContext\nsession\napplication\nout\nconfig\npage\nexception\nThe implicit objects are parsed by the container and inserted into the generated servlet code. They are available only within the jspService method and not in any declaration."
},
{"id":"14",
"q":"What is page directive?",
"answer":"A page directive is to inform the JSP engine about the headers or facilities that page should get from the environment.\nTypically, the page directive is found at the top of almost all of our JSP pages.\nThere can be any number of page directives within a JSP page (although the attribute – value pair must be unique).\nThe syntax of the include directive is: <%@ page attribute=\"value\">\n\nExample:<%@ include file=\"header.jsp\" %>"
},
{"id":"15",
"q":"What are the attributes of page directive? ",
"answer":"There are thirteen attributes defined for a page directive of which the important attributes are as follows:\nimport: It specifies the packages that are to be imported.\nsession: It specifies whether a session data is available to the JSP page.\ncontentType: It allows a user to set the content-type for a page.\nisELIgnored: It specifies whether the EL expressions are ignored when a JSP is translated to a servlet. "
},
{"id":"16",
"q":"What is the include directive? ",
"answer":"There are thirteen attributes defined for a page directive of which the important attributes are as follows:\nThe include directive is used to statically insert the contents of a resource into the current JSP.\nThis enables a user to reuse the code without duplicating it, and includes the contents of the specified file at the translation time.\nThe syntax of the include directive is as follows:\n<%@ include file = \"FileName\" %>\nThis directive has only one attribute called file that specifies the name of the file to be included. "
},
{"id":"17",
"q":"What are the JSP standard actions?",
"answer":"The JSP standard actions affect the overall runtime behavior of a JSP page and also the response sent back to the client.\nThey can be used to include a file at the request time, to find or instantiate a JavaBean, to forward a request to a new page, to generate a browser-specific code, etc.\n\nEx: include, forward, useBean,etc. object "
},
{"id":"18",
"q":"What are the standard actions available in JSP? ",
"answer":"The standard actions available in JSP are as follows:\n<jsp:include>: It includes a response from a servlet or a JSP page into the current page. It differs from an include directive in that it includes a resource at request processing time, whereas the include directive includes a resource at translation time.\n<jsp:forward>: It forwards a response from a servlet or a JSP page to another page.\n<jsp:useBean>: It makes a JavaBean available to a page and instantiates the bean.\n<jsp:setProperty>: It sets the properties for a JavaBean.\n<jsp:getProperty>: It gets the value of a property from a JavaBean component and adds it to the response.\n<jsp:param>: It is used in conjunction with <jsp:forward>;, <jsp:, or plugin>; to add a parameter to a request. These parameters are provided using the name-value pairs.\n<jsp:plugin>: It is used to include a Java applet or a JavaBean in the current JSP page. "
},
{"id":"19",
"q":"What is the <jsp:useBean> standard action?",
"answer":"The <jsp:useBean> standard action is used to locate an existing JavaBean or to create a JavaBean if it does not exist. It has attributes to identify the object instance, to specify the lifetime of the bean, and to specify the fully qualified classpath and type. "
},
{"id":"20",
"q":"What are the scopes available in <jsp:useBean>?",
"answer":"The scopes available in <jsp:useBean> are as follows:\n\npage scope:: It specifies that the object will be available for the entire JSP page but not outside the page.\n\nrequest scope: It specifies that the object will be associated with a particular request and exist as long as the request exists.\n\napplication scope: It specifies that the object will be available throughout the entire Web application but not outside the application.\n\nsession scope: It specifies that the object will be available throughout the session with a particular client."
},
{"id":"21",
"q":"Differentiate between <jsp:include page=…> and <%@include file=…>.",
"answer":"Both these tags include information from 1 page to another.\nThe first tag acts as a function call between two Jsp’s. It is executed each time client page is accessed by the client. It is useful to modularize the web application. New content is included in the output.\n\nThe second tag content of file is textually embedded having similar directive. The changed content is not included in the output. It is helpful when code from one jsp is required by several jsp’s."
},
{"id":"22",
"q":"Can constructor be used instead of init(), to initialize servlet?",
"answer":"Yes, it is possible. But it is not preferred because init() was developed because earlier Java versions could not invoke constructors with arguments dynamically. So they could not assign a servletConfig. Today, however, servlet containers still call only no-arg constructor. So there is no access to servletContext or servletConfig. "
},
{"id":"23",
"q":"Explain JSP Output comments?",
"answer":"They are comments that can be viewed in HTML Source File."
},{"id":"24",
"q":" Define Expression ",
"answer":"Expression tag is used to insert Java values directly in the output. Its syntax is <%=expression%>\n\nIt contains a scripting language expression that is evaluated, then converted to a string, and then inserted where the expression comes in JSP file."
},{"id":"25",
"q":"Define Composition. ",
"answer":"Composition has a stronger relationship with the object than Aggregation."
},{"id":"26",
"q":"Define JSP Scriptlet.",
"answer":"It a JSP tag that encloses Java code in JSP pages. Their syntax is <% %>. Code written in scriptlet executes every time the program is run."
},{"id":"27",
"q":"How can information from one JSP be passed to another JSP?",
"answer":"The tag <Jsp:param> allows us to pass information between multiple Jsp’s."
},{"id":"28",
"q":"Explain handling of runtime exceptions. ",
"answer":"Errorpage attribute is used to uncatch the run-time exceptions forwarded automatically to an error processing page.\nIt redirects the browser to JSP page error.jsp if any uncaught exception is faces during request handling. It is an error processing page."
},{"id":"29",
"q":"Explain the various scope values for <jsp:useBean> tag.",
"answer":"<jsp:useBean> tag is used to use any java object in the jsp page. Some scope values are :\n1)application\n2)request\n3)page\n4)session"
},{"id":"30",
"q":"Can Static method be Override? ",
"answer":"We can declare static methods with same signature in subclass,but it is not considered overriding as there won’t be any run-time polymorphism.Hence the answer is ‘No’."
},{"id":"31",
"q":"Explain JSP directives. ",
"answer":"JSP directives are messages to JSP Engine.They serve as a message from page to container and control the processing of the entire page.They can set global values like class declaration. They do not produce output and are enclosed in <%@….%>"
},{"id":"32",
"q":"What are standard actions in JSP?",
"answer":"They affect overall runtime behaviour of a page and response sent to the client.\nThey are used to include a file at request time, to instantiate a JavaBean or find one.\nThey are also used to generate a browser-specific code or forward a request to a new page. "
},{"id":"33",
"q":"What are the different JSP scripting elements?",
"answer":"There are three types of scripting language elements:\nDeclarations,\nScriptlets, and\nExpressions. "
},{"id":"34",
"q":"What is a JSP declaration?",
"answer":"JSP Declarations help to declare the class variables and methods in a JSP page.\nThey get initialized along with the initialization of the class.\nEverything in a <declaration> is accessible to the whole JSP page.\nYou can encircle a declaration block within the <%! And %> tags. "
},{"id":"35",
"q":"What is the include directive?",
"answer":"Its purpose is to attach the static resources to the current JSP page during the translation process. The include directive syntax is as follows:\n<%@ include file = “File-Name” %>\nThe include directive statically embeds the contents of a resource into the current JSP.\nIt allows a user to reuse the code without duplicating it and inserts the data of the target file during JSP translation.\nThis directive has only one attribute called <file> that specifies the name of the file to include."
},{"id":"36",
"q":"Define the scopes available with the <jsp: useBean>?",
"answer":"Page Scope: Tells the bean object is available for the entire JSP page without any external access.\n\nRequest Scope: Signifies the object can link with a particular request and persist till the time request lasts.\n\nSession Scope: States that the bean object is available throughout the session.\n\nApplication Scope: Specifies the bean object is available throughout the entire Web application discarding any external access. "
},{"id":"37",
"q":"What is the right way to disable scripting?",
"answer":"You can disable the scripting by changing the <scripting-invalid> element of the deployment descriptor (DD) to true. It is a child element of the <jsp-property-group> tag. You can only set it to a boolean value. Please check out the below sample to disable scripting.\n\n<jsp-property-group>\n<url-pattern>*.jsp</url-pattern>\n<scripting-invalid>true</scripting-invalid>\n</jsp-property-group> "
},{"id":"38",
"q":"What is the right way to declare a method in a JSP page?",
"answer":"You can declare a method in a JSP page as a declaration.\nLater you can call this method from any other methods of the JSP expressions or scriptlets.\nFor your note, there is no direct access allowed to the JSP implicit objects (request, response, and session, etc.).\nBut you can pass the JSP variables as parameters to the method which is declared."
},{"id":"39",
"q":"Is it possible from a JSP page to process HTML form content? ",
"answer":"Yes. You can fetch the data from the input elements of the form by using the request’s implicit object. It lies either as a scriptlet or an expression. Next, there is no need to implement any HTTP methods like goGet() or doPost() in the JSP page."
},{"id":"40",
"q":"Is JSP technology extensible? ",
"answer":"YES. JSP technology is indeed extensible as it allows to create custom actions or tags for a large no. of use cases. JSTL libraries enable this functionality in a JSP page."
},{"id":"41",
"q":"What is the best way to implement a thread-safe JSP page? ",
"answer":"Apply the SingleThreadModel Interface in the JSP page.You can get this done by adding the directive given in the below example.\n<%@page isThreadSafe=”false” %>"
},{"id":"42",
"q":"How to restrict the caching of the JSP/servlet output on the client side? ",
"answer":"Use the relevant HTTP header attributes to block the caching of JSP page output by the browser."
},{"id":"43",
"q":"List out the major difference between a cookie and a JSP session?",
"answer":"Sessions always preserved on the server-side while the cookies have their way on the client-end."
},{"id":"44",
"q":"Explain jsp:plugin action.",
"answer":"This action helps in insertion of a specific object in the browser or embed the element needed to specify the running of applet using Java plugin."
},{"id":"45",
"q":"What is Translation Phase?",
"answer":"JSP engine translates and compiles a JSP file to a servlet. This servlet moves to the execution phase where requests and responses are handled. They are compiled for the first time they are accessed unless manually compiled ahead of time. The manual or explicit compilation is useful for long and convoluted programs."
},{"id":"46",
"q":"Give uses of Object Cloning.",
"answer":"Object cloning is used to create an exact copy of an object by typing the same code or using various other techniques. "
},{"id":"47",
"q":"How can you avoid scriptlet code in JSP?",
"answer":"JavaBeans or Custom Tags can be used instead of scriptlet code."
},{"id":"48",
"q":"Explain the jspDestroy() method. ",
"answer":"Whenever a JSP page is about to be destroyed, the container invokes the jspDestroy() method from the javax.servlet.jsp.JspPage interface. Servlets destroy methods are similar to it. It can be easily overridden to perform cleanup, like when closing a database connection. "
},{"id":"49",
"q":"Explain the <jsp:param> action. ",
"answer":"It is an action used with include or forward standard actions. It helps in passing the parameter names and values to a resource. "
},{"id":"50",
"q":"What is a JSP expression? ",
"answer":"A JSP expression helps to write an output without using the <out.print statement>. You can see it as a shorthand description for the scriptlets. And as usual, you delimit an expression using the <%= and %> tags.\nEnding the expression with a semicolon is not mandatory, as it gets automatically added to the <expressions> within the expression tags."
}
]
}
"iq":[{"id":"1",
"q":"Explain JSP and tell its uses.",
"answer":"JSP stands for Java Server Pages. It is a presentation layer technology independent of platform. It comes with SUN’s J2EE platforms. They are like HTML pages but with Java code pieces embedded in them. They are saved with a .jsp extension. They are compiled using JSP compiler in the background and generate a Servlet from the page. "
},
{"id":"2",
"q":"What is the requirement of a tag library? ",
"answer":"A collection of custom tags is called a Tag Library. Recurring tasks are handled more easily and reused across multiple applications to increase productivity. They are used by Web Application designers who focus on presentation rather than accessing database or other services. Some popular libraries are String tag library and Apache display tag library. "
},
{"id":"3",
"q":"Explain JSP Technology.",
"answer":"JSP is a standard extension of Java and is defined on top of Servlet extensions. Its goal is to simplify management and creation of dynamic web pages. It is platform-independent, secure, and it makes use of Java as a server side scripting language."
},
{"id":"4",
"q":"How does a servlet differ from the JSP?",
"answer":"The JSP and Servlets are both web components and functionally similar. In fact, a JSP gets transformed into the servlet at run-time. The main variation between the two is that JSPs are useful for operations that are HTML-intensive whereas the Servlets are best-suited for tasks that are Java-intensive. The below example can elaborate the difference clearly.\n\nExample: A web application which follows the MVC model separates the components into three groups.\n\nModel- Represents the modules that contain application data e.g. Java beans.\n\nViews- It is the part of the application that displays information. e.g. dynamically generated HTML, JSP handles this part very well.\n\nControllers- Its job is to work as a carrier between the model and the view. The controller places the user entered information into the model and forwards it to the next view. Servlets fulfill this purpose perfectly. "
},
{"id":"5",
"q":"What are the JSP lifecycle phases? ",
"answer":"Translation\nCompilation\nClass Loading\nInstantiation\nInitialization\nRequest Processing\nDestroy "
},
{"id":"6",
"q":"What are JSP lifecycle methods? ",
"answer":"The JSP container executes the jspInit() method the first time it initializes the JSP.Whenever the container receives a request, it invokes the _jspService() method, processes the request and generates a response.The container calls the jspDestroy() method for cleaning up the memory allocated for the JSP. "
},
{"id":"7",
"q":"Which of the JSP life cycle methods you can override?",
"answer":"You can’t override the _jspService() Method within a JSP page. However, there are two approaches you can take to override the jspInit() and jspDestroy() methods within the JSP page.\n\njspInit() Can be quite useful for reserving resources like DB connections, N/W connections, and so forth for the JSP page. It is deemed as a good programming practice to free any allocated resources in the jspDestroy() method."
},
{"id":"8",
"q":"Is it possible for one JSP to extend another java class if yes how?",
"answer":"Yes it is possible we can extends another JSP using this <%@ include page extends=\"classname\" %> it’s a perfectly correct because when JSP is converted to servlet its implements javax.servlet.jsp.HttpJspPage interface, so for jsp page its possible to extend another java class . This question can be tricky if you don’t know some basic fact J, though it's not advisable to write java code in jsp instead it's better to use expression language and tag library."
},
{"id":"9",
"q":"what are the implicit Object ",
"answer":"This is a fact based interview question what it checks is how much coding you do in JSP if you are doing it frequently you definitely know them. Implicit object is the object that is created by web container provides to a developer to access them in their program using JavaBeans and Servlets. These objects are called implicit objects because they are automatically instantiated.they are bydefault available in JSP page.They are request, response, pageContext, session, and application, out, config, page, and exception."
},
{"id":"10",
"q":"How can you pass information form one jsp to included jsp:",
"answer":"This JSP interview question is little tricky and fact based. Using < Jsp: param> tag we can pass parameter from main jsp to included jsp page\n\nExample:\n<jsp:include page=\"newbid.jsp\" flush=\"true\">\n<jsp:param name=\"price\" value=\"123.7\"/>\n<jsp:param name=\"quantity\" value=\"4\"/>"
},
{"id":"11",
"q":"what is the need of tag library?",
"answer":"Ans tag library is a collection of custom tags. Custom actions helps recurring tasks will be handled more easily they can be reused across more than one application and increase productivity. JSP tag libraries are used by Web application designers who can focus on presentation issues rather than being concerned with how to access databases and other enterprise services. Some of the popular tag libraries are Apache display tag library and String tag library."
},
{"id":"12",
"q":"What are JSP directives?",
"answer":"JSP directives are messages for the JSP engine. i.e., JSP directives serve as a message from a JSP page to the JSP container and control the processing of the entire pageThey are used to set global values such as a class declaration, method implementation, output content type, etc.They do not produce any output to the client.\nDirectives are always enclosed within <%@ ….. %> tag.\n\nEx: page directive, include directive, etc."
},
{"id":"13",
"q":"What are implicit objects in JSP?",
"answer":"Implicit objects in JSP are the Java objects that the JSP Container makes available to developers in each page. These objects need not be declared or instantiated by the JSP author. They are automatically instantiated by the container and are accessed using standard variables; hence, they are called implicit objects.The implicit objects available in JSP are as follows:\nrequest\nresponse\npageContext\nsession\napplication\nout\nconfig\npage\nexception\nThe implicit objects are parsed by the container and inserted into the generated servlet code. They are available only within the jspService method and not in any declaration."
},
{"id":"14",
"q":"What is page directive?",
"answer":"A page directive is to inform the JSP engine about the headers or facilities that page should get from the environment.\nTypically, the page directive is found at the top of almost all of our JSP pages.\nThere can be any number of page directives within a JSP page (although the attribute – value pair must be unique).\nThe syntax of the include directive is: <%@ page attribute=\"value\">\n\nExample:<%@ include file=\"header.jsp\" %>"
},
{"id":"15",
"q":"What are the attributes of page directive? ",
"answer":"There are thirteen attributes defined for a page directive of which the important attributes are as follows:\nimport: It specifies the packages that are to be imported.\nsession: It specifies whether a session data is available to the JSP page.\ncontentType: It allows a user to set the content-type for a page.\nisELIgnored: It specifies whether the EL expressions are ignored when a JSP is translated to a servlet. "
},
{"id":"16",
"q":"What is the include directive? ",
"answer":"There are thirteen attributes defined for a page directive of which the important attributes are as follows:\nThe include directive is used to statically insert the contents of a resource into the current JSP.\nThis enables a user to reuse the code without duplicating it, and includes the contents of the specified file at the translation time.\nThe syntax of the include directive is as follows:\n<%@ include file = \"FileName\" %>\nThis directive has only one attribute called file that specifies the name of the file to be included. "
},
{"id":"17",
"q":"What are the JSP standard actions?",
"answer":"The JSP standard actions affect the overall runtime behavior of a JSP page and also the response sent back to the client.\nThey can be used to include a file at the request time, to find or instantiate a JavaBean, to forward a request to a new page, to generate a browser-specific code, etc.\n\nEx: include, forward, useBean,etc. object "
},
{"id":"18",
"q":"What are the standard actions available in JSP? ",
"answer":"The standard actions available in JSP are as follows:\n<jsp:include>: It includes a response from a servlet or a JSP page into the current page. It differs from an include directive in that it includes a resource at request processing time, whereas the include directive includes a resource at translation time.\n<jsp:forward>: It forwards a response from a servlet or a JSP page to another page.\n<jsp:useBean>: It makes a JavaBean available to a page and instantiates the bean.\n<jsp:setProperty>: It sets the properties for a JavaBean.\n<jsp:getProperty>: It gets the value of a property from a JavaBean component and adds it to the response.\n<jsp:param>: It is used in conjunction with <jsp:forward>;, <jsp:, or plugin>; to add a parameter to a request. These parameters are provided using the name-value pairs.\n<jsp:plugin>: It is used to include a Java applet or a JavaBean in the current JSP page. "
},
{"id":"19",
"q":"What is the <jsp:useBean> standard action?",
"answer":"The <jsp:useBean> standard action is used to locate an existing JavaBean or to create a JavaBean if it does not exist. It has attributes to identify the object instance, to specify the lifetime of the bean, and to specify the fully qualified classpath and type. "
},
{"id":"20",
"q":"What are the scopes available in <jsp:useBean>?",
"answer":"The scopes available in <jsp:useBean> are as follows:\n\npage scope:: It specifies that the object will be available for the entire JSP page but not outside the page.\n\nrequest scope: It specifies that the object will be associated with a particular request and exist as long as the request exists.\n\napplication scope: It specifies that the object will be available throughout the entire Web application but not outside the application.\n\nsession scope: It specifies that the object will be available throughout the session with a particular client."
},
{"id":"21",
"q":"Differentiate between <jsp:include page=…> and <%@include file=…>.",
"answer":"Both these tags include information from 1 page to another.\nThe first tag acts as a function call between two Jsp’s. It is executed each time client page is accessed by the client. It is useful to modularize the web application. New content is included in the output.\n\nThe second tag content of file is textually embedded having similar directive. The changed content is not included in the output. It is helpful when code from one jsp is required by several jsp’s."
},
{"id":"22",
"q":"Can constructor be used instead of init(), to initialize servlet?",
"answer":"Yes, it is possible. But it is not preferred because init() was developed because earlier Java versions could not invoke constructors with arguments dynamically. So they could not assign a servletConfig. Today, however, servlet containers still call only no-arg constructor. So there is no access to servletContext or servletConfig. "
},
{"id":"23",
"q":"Explain JSP Output comments?",
"answer":"They are comments that can be viewed in HTML Source File."
},{"id":"24",
"q":" Define Expression ",
"answer":"Expression tag is used to insert Java values directly in the output. Its syntax is <%=expression%>\n\nIt contains a scripting language expression that is evaluated, then converted to a string, and then inserted where the expression comes in JSP file."
},{"id":"25",
"q":"Define Composition. ",
"answer":"Composition has a stronger relationship with the object than Aggregation."
},{"id":"26",
"q":"Define JSP Scriptlet.",
"answer":"It a JSP tag that encloses Java code in JSP pages. Their syntax is <% %>. Code written in scriptlet executes every time the program is run."
},{"id":"27",
"q":"How can information from one JSP be passed to another JSP?",
"answer":"The tag <Jsp:param> allows us to pass information between multiple Jsp’s."
},{"id":"28",
"q":"Explain handling of runtime exceptions. ",
"answer":"Errorpage attribute is used to uncatch the run-time exceptions forwarded automatically to an error processing page.\nIt redirects the browser to JSP page error.jsp if any uncaught exception is faces during request handling. It is an error processing page."
},{"id":"29",
"q":"Explain the various scope values for <jsp:useBean> tag.",
"answer":"<jsp:useBean> tag is used to use any java object in the jsp page. Some scope values are :\n1)application\n2)request\n3)page\n4)session"
},{"id":"30",
"q":"Can Static method be Override? ",
"answer":"We can declare static methods with same signature in subclass,but it is not considered overriding as there won’t be any run-time polymorphism.Hence the answer is ‘No’."
},{"id":"31",
"q":"Explain JSP directives. ",
"answer":"JSP directives are messages to JSP Engine.They serve as a message from page to container and control the processing of the entire page.They can set global values like class declaration. They do not produce output and are enclosed in <%@….%>"
},{"id":"32",
"q":"What are standard actions in JSP?",
"answer":"They affect overall runtime behaviour of a page and response sent to the client.\nThey are used to include a file at request time, to instantiate a JavaBean or find one.\nThey are also used to generate a browser-specific code or forward a request to a new page. "
},{"id":"33",
"q":"What are the different JSP scripting elements?",
"answer":"There are three types of scripting language elements:\nDeclarations,\nScriptlets, and\nExpressions. "
},{"id":"34",
"q":"What is a JSP declaration?",
"answer":"JSP Declarations help to declare the class variables and methods in a JSP page.\nThey get initialized along with the initialization of the class.\nEverything in a <declaration> is accessible to the whole JSP page.\nYou can encircle a declaration block within the <%! And %> tags. "
},{"id":"35",
"q":"What is the include directive?",
"answer":"Its purpose is to attach the static resources to the current JSP page during the translation process. The include directive syntax is as follows:\n<%@ include file = “File-Name” %>\nThe include directive statically embeds the contents of a resource into the current JSP.\nIt allows a user to reuse the code without duplicating it and inserts the data of the target file during JSP translation.\nThis directive has only one attribute called <file> that specifies the name of the file to include."
},{"id":"36",
"q":"Define the scopes available with the <jsp: useBean>?",
"answer":"Page Scope: Tells the bean object is available for the entire JSP page without any external access.\n\nRequest Scope: Signifies the object can link with a particular request and persist till the time request lasts.\n\nSession Scope: States that the bean object is available throughout the session.\n\nApplication Scope: Specifies the bean object is available throughout the entire Web application discarding any external access. "
},{"id":"37",
"q":"What is the right way to disable scripting?",
"answer":"You can disable the scripting by changing the <scripting-invalid> element of the deployment descriptor (DD) to true. It is a child element of the <jsp-property-group> tag. You can only set it to a boolean value. Please check out the below sample to disable scripting.\n\n<jsp-property-group>\n<url-pattern>*.jsp</url-pattern>\n<scripting-invalid>true</scripting-invalid>\n</jsp-property-group> "
},{"id":"38",
"q":"What is the right way to declare a method in a JSP page?",
"answer":"You can declare a method in a JSP page as a declaration.\nLater you can call this method from any other methods of the JSP expressions or scriptlets.\nFor your note, there is no direct access allowed to the JSP implicit objects (request, response, and session, etc.).\nBut you can pass the JSP variables as parameters to the method which is declared."
},{"id":"39",
"q":"Is it possible from a JSP page to process HTML form content? ",
"answer":"Yes. You can fetch the data from the input elements of the form by using the request’s implicit object. It lies either as a scriptlet or an expression. Next, there is no need to implement any HTTP methods like goGet() or doPost() in the JSP page."
},{"id":"40",
"q":"Is JSP technology extensible? ",
"answer":"YES. JSP technology is indeed extensible as it allows to create custom actions or tags for a large no. of use cases. JSTL libraries enable this functionality in a JSP page."
},{"id":"41",
"q":"What is the best way to implement a thread-safe JSP page? ",
"answer":"Apply the SingleThreadModel Interface in the JSP page.You can get this done by adding the directive given in the below example.\n<%@page isThreadSafe=”false” %>"
},{"id":"42",
"q":"How to restrict the caching of the JSP/servlet output on the client side? ",
"answer":"Use the relevant HTTP header attributes to block the caching of JSP page output by the browser."
},{"id":"43",
"q":"List out the major difference between a cookie and a JSP session?",
"answer":"Sessions always preserved on the server-side while the cookies have their way on the client-end."
},{"id":"44",
"q":"Explain jsp:plugin action.",
"answer":"This action helps in insertion of a specific object in the browser or embed the element needed to specify the running of applet using Java plugin."
},{"id":"45",
"q":"What is Translation Phase?",
"answer":"JSP engine translates and compiles a JSP file to a servlet. This servlet moves to the execution phase where requests and responses are handled. They are compiled for the first time they are accessed unless manually compiled ahead of time. The manual or explicit compilation is useful for long and convoluted programs."
},{"id":"46",
"q":"Give uses of Object Cloning.",
"answer":"Object cloning is used to create an exact copy of an object by typing the same code or using various other techniques. "
},{"id":"47",
"q":"How can you avoid scriptlet code in JSP?",
"answer":"JavaBeans or Custom Tags can be used instead of scriptlet code."
},{"id":"48",
"q":"Explain the jspDestroy() method. ",
"answer":"Whenever a JSP page is about to be destroyed, the container invokes the jspDestroy() method from the javax.servlet.jsp.JspPage interface. Servlets destroy methods are similar to it. It can be easily overridden to perform cleanup, like when closing a database connection. "
},{"id":"49",
"q":"Explain the <jsp:param> action. ",
"answer":"It is an action used with include or forward standard actions. It helps in passing the parameter names and values to a resource. "
},{"id":"50",
"q":"What is a JSP expression? ",
"answer":"A JSP expression helps to write an output without using the <out.print statement>. You can see it as a shorthand description for the scriptlets. And as usual, you delimit an expression using the <%= and %> tags.\nEnding the expression with a semicolon is not mandatory, as it gets automatically added to the <expressions> within the expression tags."
}
]
}