PCMC: 9960935965, KOTHRUD: 9960935600

JSP Interview Questions And Answers - Aspire Techsoft

 

 Q1. Explain JSP and tell its uses. 

ANS: JSP stands for Java Server Pages. It is a presentation layer technology independent of the 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 a JSP compiler in the background and generate a Servlet from the page. 

 

Q2. Explain JSP Technology. 

ANS: JSP is a standard extension of Java and is defined on top of Servlet extensions. Its goal is to simplify the management and creation of dynamic web pages. It is platform-independent, and secure, and it makes use of Java as a server-side scripting language. 

 

Q3. Is JSP technology extensible? 

ANS: Yes, JSP is easily extensible by use and modification of tags, or custom actions, encapsulated in tag libraries. 

 

Q4. Can a subsequent request be accessed with one’s servlet code, if a request attribute is already sent in his JSP? 

ANS: The request goes out of scope, thus, it cannot be accessed. However, if a request attribute is set in one’s servlet, then it can be accessed in his JSP. A JSP is a server-side component and the page is translated to a Java servlet, and then executed. Only HTML code is given as output. 

 

Q5. How can the output of JSP or servlet page be prevented from being cached by the browser? 

ANS: Using appropriate HTTP header attributes to prevent the dynamic content output by a JSP page from being cached by the browser. 

 

Q6. How to restrict page errors displayed on a JSP page? 

ANS: By setting up an “ErrorPage” attribute of PAGE directory to the name of the error page in the JSP page, and then in the error jsp page set “isErrorpage=” TRUE” " errors can be stopped from getting displayed. 

 

Q7. Explain lifecycle methods. 

ANS: 1) jsplnit(): The container calls this to initialize the servlet instance. It is called only once for the servlet instance and precedes every other method. 

2) _jspService(): The container calls this for each request and passes it on to the objects. 

3) jspDestroy(): It is called by the container just before the destruction of the instance. 

 

Q8. Define JSP Scriptlet. 

ANS: It is a JSP tag that encloses Java code in JSP pages. Their syntax is <% %>. Code written in scriptlet executes every time the program is run. 

 

Q9. Explain JSP directives. 

ANS: 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 <%@….%> 

 

Q10. Explain page Directives. 

ANS: Page Directives inform the JSP Engine about headers and facilities that the page receives from the environment. It is found at the top of all JSP pages. Its syntax is <%@ page attribute=”value”> 

 

Q11. Explain client and server-side validation. 

ANS: Javascript is used for the client-side validation. It takes place within the browser. Javascript is used to submit the form data if validation is successful. Validation errors require no extra network trip because the form cannot be submitted. Validation is also carried out in the server after submission. If validation fails, an extra network trip is required to resend the form to the client. 

 

Q12. What is the Translation Phase? 

ANS: The 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. 

 

Q13. Explain the jspDestroy () method. 

ANS: Whenever a JSP page is about to be destroyed, the container invokes the jspDestroy() method from the java.servlet.jsp.JspPage interface. Servlet destroy methods are similar to it. It can be easily overridden to perform cleanup, like when closing a database connection. 

 

Q14. How is JSP better than Servlet technology? 

ANS: JSP is a technology on the server’s side to makes content generation simple. They are document-centric, whereas servlets are programs. A Java server page can contain fragments of Java programs, which execute and instantiate Java classes. However, they occur insidethe  HTML template file. It provides the framework for the development of a Web Application. 

 

Q15. When are JSP declarations made? 

ANS: A JSP declaration is a claim on one or more variables or methods used in Java code a time in the JSP file. You must declare a variable or method before using it in the JSP file. 

Browse our course links: Java Classes in Pune

To Join our FREE DEMO Session: Click Here

 

Q16. What are JSP comments? 

ANS: JSP comments are the statements that the JSP container should ignore and are helpful to hide or "comment out" part of the JSP page.

 

17. When are JSP actions required? 

ANS: JSP actions control the behavior of the servlet engine. The JSP actions use constructs in XML syntax to dynamically insert a file, direct the user to another page, generate HTML for the Java plugin, or reuse JavaBeans components. 

 

Q18. Where are page directives used? 

ANS: The page directive provides instructions to the container containing the current JSP page and can be used anywhere on the JSP page. 

 

Q19. What is a buffer attribute? 

ANS: The buffer attribute is a command specifying buffering characteristics for the server output response object. 

 

Q20. What is an extended attribute? 

ANS: The extended attribute specifies which superclass the generated Servlet must extend. 

 

Q21. What is the import attribute? 

ANS: The import attribute serves the same as the Java import statement. Its value is the name of the package that is to be imported. 

 

Q22. What does the id and scope attribute mean in the action elements? 

ANS: Id attribute − this identifies the Action element and sees the action to be referenced is taken inside the JSP page. 

Scope attribute − this attribute is used in identifying the Action element's lifecycle. 

Both attributes are directly related, as the scope attribute determines the lifespan of the object associated with the id. 

 

Q23. What the difference is between include action and include directive? 

ANS: The include directive is used to insert a file when the JSP page is translated into a servlet. They include action inserts in the file when the page is requested. 

 

Q24. How can you read a request header information? 

ANS: By using the getHeaderNames() method of HttpServletRequest to read the HTTP header information. 

 

Q25. What is the session object? 

ANS: The session object is an instance of javax.servlet.http.HttpSession. It helps in tracking client sessions between client requests. 

 

Q26. What is an application object? 

ANS: An application object is a direct wrapper around the Servlet Context object for the created Servlet and, in reality, an instance of a javax. servlet.ServletContext object. This object is a representation of the JSP page during its entire lifecycle. This object is created when the JSP page is initialized and is removed when the JSP page is deleted using the jspDestroy () function. 

 

Q26. What is a page object? 

ANS: The page object is a direct reference to the page instance. This object is a representation of the complete JSP page. 

 

Q27.Where are the filters used in JSP? 

ANS: Filters can be used when deploying a descriptor file web.xml and mapping to servlet or JSP names or URL patterns in the application's deployment descriptor. The JSP container starts the web application and creates an instance for each filter declared in the deployment descriptor. These filters are then executed in the order declared in the deployment descriptor. 

 

Q28. What are cookies? 

ANS: Cookies are text files stored on the client's computer for tracking the information. 

 

Q29. Describe the working procedure of cookies. 

ANS: Cookies are linked to the HTTP header. The browser is first configured to store cookies and this information until expiry. When the path of any page matches the cookie's domain, it is then reloaded to the server. 

 

Q30. Where are the uploaded files stored? 

ANS: These files are stored in the program name, or the directory name could also be added using an external configuration such as a context-param element in web.xml.

Browse our course links: Java Classes in Pune

To Join our FREE DEMO Session: Click Here

 

Get More Information