• +91 9723535972
  • info@interviewmaterial.com

JSP Interview Questions and Answers

JSP Interview Questions and Answers

Question - 91 : - Mention the advantages of JSP over Pure Servlets?

Answer - 91 : -

Some of the Major Advantages of JSP over Pure Servlets are as discussed below:

  • It is more convenient to write and modify normal HTML than to have plenty of println statements that generate the HTML.
  • Embedding of Java code in HTML pages.
  • Platform independence.
  • Creation of database-driven Web applications.
  • Server-side programming capabilities.

Question - 92 : - What is Auto-Flush Attribute?

Answer - 92 : - The autoFlush attribute is used to specify if a 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 by default indicates automatic buffer flushing and a value of false throws an exception.

Question - 93 : - What do you mean by isScriptingEnabled Attribute?

Answer - 93 : - isScriptingEnabled attribute determines if scripting elements are allowed for use or not. The default value is true and it 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/declarations.

Question - 94 : - What are the steps involved in reading data from a form using JSP?

Answer - 94 : -

The data parsing is a JSP is Automatic. It is done through the following steps depending on the situation.

  • getParameter(): request.getParameter() method is called to get the value of the form parameter.
  • getParameterValues(): This method is called if the parameter appears more than once and returns multiple values.
  • getParameterNames(): This method is called if the user wants a complete list of all parameters in the current request.
  • getInputStream(): This method is used to read binary data stream coming from the client.

Question - 95 : - How are cookies set in JSP?

Answer - 95 : -

Setting cookies with JSP involves the following steps:

  • Creating a Cookie object: Cookie constructor is called with a cookie name and a cookie value, both are strings.
  • Setting the maximum age: setMaxAge is used to specify the length of the cookie(in seconds) should be valid.
  • Sending the cookie into the HTTP response headers: response.addCookie is used to add cookies in the HTTP response header.

Question - 96 : - How do you delete the Session Data?

Answer - 96 : -

Deleting the Session Data involves the following steps.

  • Remove a particular attribute: public void removeAttribute(String name) method is called to delete the value associated with the particular key.
  • Delete the whole session: public void invalidate() method is called to discard an entire session.
  • Setting the Session timeout: public void setMaxInactiveInterval(int interval) method is called to set the timeout for a session individually.
  • Log the user out: The logout is called to log the client out of the Web server and invalidate all sessions belonging to all the users.
  • web.xml Configuration: In Tomcat, using the above-mentioned methods, one can configure session time out in web.xml file as follows.

Question - 97 : - How to delete a Cookie in JSP?

Answer - 97 : -

The following code snippet is followed to delete a cookie in JSP.

  • Cookie mycookie = new Cookie("name","value");
  • response.addCookie(mycookie);
  • Cookie killcookie = new Cookie("mycookie","value");
  • killcookie . set MaxAge ( 0 );
  • killcookie . set Path (" / ");
  • killcookie . addCookie ( killcookie 1 );

Question - 98 : - Explain the difference between forward and sendRedirect?

Answer - 98 : -

When a forward request is called, the request is sent to a different resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completely with in the web container.

When a sendRedirtect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Since the browser issues a completely new request any objects that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward.

Question - 99 : - Why are JSP pages preferred for creating web-based client program?

Answer - 99 : - JSP is preferred for creating web-based client program. Because no plug-ins/security policy files are needed on the client systems whereas applet does. Also, JSP pages enable cleaner and more module application design because they provide a way to separate applications programming from web page design. This means personnel involved in web page design do not need to understand Java programming language syntax to do their jobs.

Question - 100 : - How can you make the Finally Clause not to fail to execute?

Answer - 100 : -

It is possible to make the Finally Clause to not to fail by using System.exit(1); in the try block.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners