jsp-interview

List of Top 20 Java JSP Interview Questions and Answers for freshers and experienced are below:


1. What is JSP?
--> JSP Stands for Java server pages. JSP is Java technology which is used by developers across the world to create dynamically generated websites with the easy use of other documents like HTML, XML. 

This technology of java allows developers to include java code and some pre defined actions into static content. Java server pages are compiled into java servlet by the java compiler or the java compiler may directly generate the byte code for the servlet.

2. How servlet differ from JSP?
--> Both Servlet and Java Server Pages are API which generate dynamic web content. A servlet is nothing but a java class which implements the interface to run within a web and on the other hand Java server pages is a bit complicated thing which contain a mixture of Java scripts, Java directives, Java elements and HTML. 

The main difference among both servlet and Java server pages is that JSP is document oriented and servlet on the other hand act likes a program.

3. What are the advantages of JSP?
--> There are many advantages of JSP and JSP is very much preferred by every coder. The main advantage of JSP over anything is its auto compilation and the length of code is reduced by using custom tags and tag library. Secondly, it is portable that is it works on all operating system and non – Microsoft web servers. 

Java components can be easily embedded into the dynamic pages. JSP have all the features of java and can easily separate dynamic part from the static part of the page.

4. What are the implicit objects in JSP?

--> There are all total 9 implicit objects in JSP. Application interface refers to the web application’s interface whereas Session interface refers to the user’s session. 

Request interface refers to the page which is currently requested whereas Response interface refers to the response which is currently made by the user. Config interface refers to the servlet configuration. Class like out, page, page Context and exception refers to the output stream of the page, servlet instance of the page, environment of the page, error handling respectively.

5. How JSP calls a stored procedure?
--> Java Server Pages possess all the characteristics of java and to call and have similar syntax to call a function. Functions and stored procedures of a database can be called by using the statement callable. Another way to call the stored procedure is by writing the JDBC code in between the tag of scriptlet tab.write.


6. How to override the lifecycle methods of JSP?
--> Lifecycle method jspService() cannot be overridden within a JSP page however methods like jspInit() and jspDestroy() can be overridden within a JSP page. Method jspInit() is used for allocating resource while method jspDestroy() is used to free allocated resource. 

But it should be kept in mind that during the lifecycle of a Java Server Page both the method jsplnit() and jspDestroy() is executed once and are declared as JSP declarations.

7. What is declaration in JSP?
--> In Java Server pages Declaration is used to declare and define variables and methods that can be used in the Java Server Pages. The variable which is declared is initialized once and it retain its value for every subsequent client request.

8. How a run - time application is handled in JSP?
--> In JSP the errorpage attribute of the page is used as a directive to have uncaught run – time exceptions and which is automatically forwarded to an page which processes the error. If an uncaught exception is encountered while processing the request, then the browser redirects to the JSP error page.

9. State the difference between the expression and scriptlet?
--> JSP, Expressions is used to display the values of variable or to return the values by invoking the getter methods. However, JSP expressions begins with <> and does not have semicolon at the end of the expression. Scriptlet can contain variable, method or expressions that are valid within the page scripting language. Within the scripting tags and page scripting language any valid operations can be performed.

10. Outline the difference between Java server page forward and servlet forward method?
--> The only minor difference between both the methods is that Java Server page forward method can’t forward to another JSP page in another web application or container whereas servlet forward method can do so.


11. What are custom tags and why it is needed?
--> JSP tags are extended by creating a custom set of tags which is called as tag library (taglib). The page which uses custom tags declares taglib and uniquely names, defines and associates a tag prefix to differentiate the usage of those tags.

12. How cookies is deleted in JSP?
--> There are two ways by which the cookies can be deleted in JSP. Firstly, by setting the setMaxAge() of the cookie class to zero. And secondly by setting a timer in the header file that is response. setHeader(expires {Mention the time} attribute), which will delete the cookies after that prescribed time.

13. Is it possible by a JSP page to process HTML form data?
--> Yes it is possible by simply obtaining the data from the FORM input via the request implicit object which lies with a scriptlet or expression but it doesn't require to implement any HTTP – Protocol methods like goGet() or doPost() within the JSP page.

14. How method is declared within JSP page?
--> Methods can be declared for use within JSP page as declaration and this method can be invoked within any other method which is declared or within JSP scriptlets or expressions. 

Direct access to the JSP implicit objects like request, response, session etc is forbidden within JSP methods but implicit Java server page variable is allowed to pass as parameters to the method which is declared.

15. Outline the major difference between the session and cookie?
--> Sessions are always stored in the server side whereas cookies are always stored in the client side.


16 . What is a output comment?
--> A comment that is sent to the client in the viewable page source. The JSP engine handles an output comment as un-interpreted HTML text, returning the comment in the HTML output sent to the client. You can see the comment by viewing the page source from your Web browser.

17 . What is a Hidden Comment?
--> A comment that documents the JSP page but is not sent to the client. The JSP engine ignores a hidden comment, and does not process any code within hidden comment tags. A hidden comment is not sent to the client, either in the displayed JSP page or the HTML page source. The hidden comment is useful when you want to hide part of your JSP page.

18 . What is a Expression?
--> Expressions are act as place holders for language expression, expression is evaluated each time the page is accessed.

19 . What is a Declaration?
--> It declares one or more variables or methods for use later in the JSP source file. A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as semicolons separate them. The declaration must be valid in the scripting language used in the JSP file.

20 . What are the implicit objects?
--> List them. Certain objects that are available for the use in JSP documents without being declared first. These objects are parsed by the JSP engine and inserted into the generated servlet. 
The implicit objects are:
1. request
2. response
3. pageContext
4. session
5. application
6. out
7. config
8. page
9. exception

Post a Comment

 
Top