InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 51. |
How do you set cookies in the JSP? |
|
Answer» Setting cookies with JSP involves three steps −
|
|
| 52. |
How cookies work? |
|
Answer» Cookies are usually set in an HTTP header (although JavaScript can also set a cookie directly on a browser).If the browser is configured to store cookies, it will then keep this information until the expiry date. If the user points the browser at any page that matches the path and domain of the cookie, it will resend the cookie to the server. |
|
| 53. |
What are cookies? |
|
Answer» Cookies are text files stored on the client computer and they are kept for various information tracking purpose. |
|
| 54. |
How do you define filters? |
|
Answer» Filters are defined in the deployment descriptor file web.xml and then mapped to either servlet or JSP names or URL patterns in your application's deployment descriptor. When the JSP container starts up your web application, it creates an instance of each filter that you have declared in the deployment descriptor. The filters execute in the order that they are declared in the deployment descriptor. |
|
| 55. |
What are filters? |
|
Answer» JSP Filters are Java classes that can be used in JSP Programming for the following purposes −
|
|
| 56. |
How to read form data using JSP? |
|
Answer» JSP handles form data parsing automatically using the following methods depending on the situation −
|
|
| 57. |
What is difference between GET and POST method in HTTP protocol? |
|
Answer» The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? Character. The POST method packages the information in exactly the same way as GET methods, but instead of sending it as a text string after a ? in the URL it sends it as a separate message. This message comes to the backend program in the form of the standard input which you can parse and use for your processing. |
|
| 58. |
What is a page object? |
|
Answer» This object is an actual reference to the instance of the page. It can be thought of as an object that represents the entire JSP page. The page object is really a direct synonym for the this object. |
|
| 59. |
What is a pageContext Object? |
|
Answer» The pageContext object is an instance of a javax.servlet.jsp.PageContext object. The pageContext object is used to represent the entire JSP page. This object stores references to the request and response objects for each request. The application, config, session, and out objects are derived by accessing attributes of this object. The pageContext object also contains information about the directives issued to the JSP page, including the buffering information, the errorPageURL, and page scope. |
|
| 60. |
What is a config Object? |
|
Answer» The config object is an instantiation of javax.servlet.ServletConfig and is a direct wrapper around the ServletConfig object for the generated servlet. This object allows the JSP programmer access to the Servlet or JSP engine initialization parameters such as the paths or file locations etc. |
|
| 61. |
What is an application Object? |
|
Answer» The application object is direct wrapper around the ServletContext object for the generated Servlet and in reality an instance of a javax.servlet.ServletContext object. This object is a representation of the JSP page through its entire lifecycle. This object is created when the JSP page is initialized and will be removed when the JSP page is removed by the jspDestroy() method. |
|
| 62. |
What is the session Object? |
|
Answer» The session object is an instance of javax.servlet.http.HttpSession and is used to track client session between client requests |
|
| 63. |
What is the difference between JspWriter and PrintWriter? |
|
Answer» The JspWriter object contains most of the same methods as the java.io.PrintWriter class. However, JspWriter has some additional methods designed to deal with buffering. Unlike the PrintWriter object, JspWriter throws IOExceptions. |
|
| 64. |
What is the out implicit object? |
|
Answer» The out implicit object is an instance of a javax.servlet.jsp.JspWriter object and is used to send content in a response. |
|
| 65. |
What is a response object? |
|
Answer» The response object is an instance of a javax.servlet.http.HttpServletRequest object. Just as the server creates the request object, it also creates an object to represent the response to the client. The response object also defines the interfaces that deal with creating new HTTP headers. Through this object the JSP programmer can add new cookies or date stamps, HTTP status codes etc. |
|
| 66. |
How can you read a request header information? |
|
Answer» Using getHeaderNames() method of HttpServletRequest to read the HTTP header information. This method returns an Enumeration that contains the header information associated with the current HTTP request. |
|
| 67. |
What is a request object? |
|
Answer» The request object is an instance of a javax.servlet.http.HttpServletRequest object. Each time a client requests a page the JSP engine creates a new object to represent that request. The request object provides methods to get HTTP header information including form data, cookies, HTTP methods etc. |
|
| 68. |
What implicit objects are supported by JSP? |
|
Answer» request, response, out, session, application, config, pageContext, page, Exception |
|
| 69. |
What are JSP implicit objects? |
|
Answer» JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in each page and developer can call them directly without being explicitly declared. JSP Implicit Objects are also called pre-defined variables. |
|
| 70. |
What are the different scope values for the JSP action? |
|
Answer» The scope attribute identifies the lifecycle of the Action element. It has four possible values: (a) page, (b)request, (c)session, and (d) application. |
|
| 71. |
What is Action? |
|
Answer» The plugin action is used to insert Java components into a JSP page. It determines the type of browser and inserts the <object> or <embed> tags as needed. If the needed plugin is not present, it downloads the plugin and then executes the Java component. The Java component can be either an Applet or a JavaBean. |
|
| 72. |
What is Action? |
|
Answer» The forward action terminates the action of the current page and forwards the request to another resource such as a static page, another JSP page, or a Java Servlet. The simple syntax of this action is as follows − <jsp:forward page = "Relative URL" /> |
|
| 73. |
What is action? |
|
Answer» The getProperty action is used to retrieve the value of a given property and converts it to a string, and finally inserts it into the output. |
|
| 74. |
What is action? |
|
Answer» The setProperty action sets the properties of a Bean. The Bean must have been previously defined before this action. |
|
| 75. |
What is action? |
|
Answer» The useBean action is quite versatile. It first searches for an existing object utilizing the id and scope variables. If an object is not found, it then tries to create the specified object. The simplest way to load a bean is as follows − <jsp:useBean id = "name" class = "package.class" /> |
|
| 76. |
What is the difference between include action and include directive? |
|
Answer» Unlike the include directive, which inserts the file at the time the JSP page is translated into a servlet, include action inserts the file at the time the page is requested. |
|
| 77. |
What is the function of action? |
|
Answer» This action lets you insert files into the page being generated. The syntax looks like this − <jsp:include page = "relative URL" flush = "true" /> Where page is the relative URL of the page to be included. Flush is the boolean attribute the determines whether the included resource has its buffer flushed before it is included. |
|
| 78. |
What do the id and scope attribute mean in the action elements? |
Answer»
|
|
| 79. |
What is a taglib directive? |
|
Answer» The taglib directive follows the following syntax − <% taglib uri = "uri" prefix = "prefixOfTag"> uri attribute value resolves to a location the container understands prefix attribute informs a container what bits of markup are custom actions. The taglib directive follows the following syntax − <% taglib uri = "uri" prefix = "prefixOfTag" > |
|
| 80. |
What is a include directive? |
|
Answer» The include directive is used to includes a file during the translation phase. This directive tells the container to merge the content of other external files with the current JSP during the translation phase. You may code include directives anywhere in your JSP page. The general usage form of this directive is as follows − <% include file = "relative url" > |
|
| 81. |
What is isScriptingEnabled Attribute? |
|
Answer» The isScriptingEnabled attribute determines if scripting elements are allowed for use. The default value (true) enables scriptlets, expressions, and declarations. If the attribute's value is set to false, a translation-time error will be raised if the JSP uses any scriptlets, expressions (non-EL), or declarations. |
|
| 82. |
What is isELIgnored Attribute? |
|
Answer» The isELIgnored option gives you the ability to disable the evaluation of Expression Language (EL) expressions. The default value of the attribute is true, meaning that expressions, ${...}, are evaluated as dictated by the JSP specification. If the attribute is set to false, then expressions are not evaluated but rather treated as static text. |
|
| 83. |
What is session attribute? |
|
Answer» The session attribute indicates whether or not the JSP page uses HTTP sessions. A value of true means that the JSP page has access to a builtin session object and a value of false means that the JSP page cannot access the builtin session object. |
|
| 84. |
What is language attribute? |
|
Answer» The language attribute indicates the programming language used in scripting the JSP page. |
|
| 85. |
What is isThreadSafe attribute? |
|
Answer» The isThreadSafe option marks a page as being thread-safe. By default, all JSPs are considered thread-safe. If you set the isThreadSafe option to false, the JSP engine makes sure that only one thread at a time is executing your JSP. |
|
| 86. |
What is info attribute? |
|
Answer» The info attribute lets you provide a description of the JSP. |
|
| 87. |
What is import attribute? |
|
Answer» The import attribute serves the same function as, and behaves like, the Java import statement. The value for the import option is the name of the package you want to import. |
|
| 88. |
What is extends attribute? |
|
Answer» The extends attribute specifies a superclass that the generated servlet must extend. |
|
| 89. |
What is isErrorPage attribute? |
|
Answer» The isErrorPage attribute indicates that the current JSP can be used as the error page for another JSP. The value of isErrorPage is either true or false. The default value of the isErrorPage attribute is false. |
|
| 90. |
What is errorPage attribute? |
|
Answer» The errorPage attribute tells the JSP engine which page to display if there is an error while the current page runs. The value of the errorPage attribute is a relative URL. |
|
| 91. |
What is contentType attribute? |
|
Answer» The contentType attribute sets the character encoding for the JSP page and for the generated response page. The default content type is text/html, which is the standard content type for HTML pages. |
|
| 92. |
What is autoFlush attribute? |
|
Answer» The autoFlush attribute specifies whether buffered output should be flushed automatically when the buffer is filled, or whether an exception should be raised to indicate buffer overflow. A value of true (default) indicates automatic buffer flushing and a value of false throws an exception. |
|
| 93. |
What happens when buffer is set to a value “none”? |
|
Answer» When buffer is set to “none”, servlet output is immediately directed to the response output object. |
|
| 94. |
What is a buffer attribute? |
|
Answer» The buffer attribute specifies buffering characteristics for the server output response object. |
|
| 95. |
What are various attributes Of page directive? |
|
Answer» Page directive contains the following 13 attributes.
|
|
| 96. |
What is a page directive? |
|
Answer» The page directive is used to provide instructions to the container that pertain to the current JSP page. You may code page directives anywhere in your JSP page. |
|
| 97. |
What are JSP literals? |
|
Answer» Literals are the values, such as a number or a text string, that are written literally as part of a program code. The JSP expression language defines the following literals −
|
|
| 98. |
Name some JSP actions. |
|
Answer» jsp:include, jsp:useBean,jsp:setProperty,jsp:getProperty, jsp:forward,jsp:plugin,jsp:element, jsp:attribute, jsp:body, jsp:text |
|
| 99. |
What are JSP actions? |
|
Answer» JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin. Its syntax is as follows − <jsp:action_name attribute = "value" /> |
|
| 100. |
What are the types of directive tags? |
|
Answer» The types directive tags are as follows −
|
|