JSP fresher interview question /JSP Interview Questions and Answers for Freshers & Experienced

How is JSP include directive different from JSP include action. ?

When a JSP include directive is used, the included file's code is added into the added JSP page at page
translation time, this happens before the JSP page is translated into a servlet. While if any page is included
using action tag, the page's output is returned back to the added page. This happens at runtime

Posted Date:- 2021-08-18 11:28:37

How do you pass control from one JSP page to another?

Use the following ways to pass control of a request from one servlet to another or one jsp to another.
The RequestDispatcher object ‘s forward method to pass the control.
The response.sendRedirect method

Posted Date:- 2021-08-18 11:26:57

Give a sample JSP configuration in the deployment descriptor.

Give a sample JSP configuration in the deployment descriptor.
1. Management of scriptlet elements on the page,
2. Controlling the execution of expressions in a language
3. URL pattern definition for encoding,
4. Determining the size of the buffer that is used for objects on the page
5. Identification of resource groups corresponding to a URL pattern to be processed as an XML document.

Posted Date:- 2021-08-18 11:24:28

How can I implement a thread-safe JSP page?

You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done
by adding the directive <%@ page isThreadSafe="false" % > within your JSP page.

Posted Date:- 2021-08-18 11:20:33

Give a brief about its lifecycle methods?

jsplnit(): Initially, the method is called to initialize servlet and is called only for once.
_jspService(): The container calls this method and then processes the request accordingly.
jspDestroy(): Before the demolition of instance, this method is called.

Posted Date:- 2021-08-18 11:17:16

How can we retrieve Warnings?

SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object including PreparedStatement and CallableStatement objects, or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object.

Posted Date:- 2021-08-18 11:16:05

How can you make the Finally Clause not to fail to execute?

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

Posted Date:- 2021-08-18 11:15:14

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

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.

Posted Date:- 2021-08-18 11:14:19

How do you delete the Session Data?

Deleting the Session Data involves the following steps.
1. Remove a particular attribute: public void removeAttribute(String name) method is called to delete the value associated with the particular key.
2. Delete the whole session: public void invalidate() method is called to discard an entire session.
3. Setting the Session timeout: public void setMaxInactiveInterval(int interval) method is called to set the timeout for a session individually.
4. 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.
5. web.xml Configuration: In Tomcat, using the above-mentioned methods, one can configure session time out in web.xml file as follows.

Posted Date:- 2021-08-18 11:13:29

How are cookies set in JSP?

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

Posted Date:- 2021-08-18 11:09:53

How does JSP handle run-time exceptions?

You can use the errorPage attribute of the page directive to have uncaught runtime exceptions automatically
forwarded to an error processing page.
For example:
redirects the browser to the JSP page error.jsp if an uncaught exception is encountered during request
processing. Within error.jsp, if you indicate that it is an error-processing page, via the directive:
the Throwable object describing the exception may be accessed within the error page via the exception implicit

Posted Date:- 2021-08-18 11:07:47

Mention the advantages of JSP over Pure Servlets?

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.

Posted Date:- 2021-08-18 11:06:42

How many scope objects do we have in jsp?

We have 4 scope objects.
These are useful carry the information from .jsp file to another .jsp file.
? page
? request
? application (context)
? session
In the all scope objects application scope object having highest accessibility that means we can use that scope object information from all browser as well windows also.
Session scope object data can be accessible within the same browser but all windows.
Request scope object data can be accessible only one window, once response handover to browser request scope object data will be destroyed.
Page scope object data can be accessible only within the same page.

Posted Date:- 2021-08-18 11:05:49

How are JSP(Java Server Pages) better than ASP(Active Server Pages)?

The advantages of JSP over ASP are as follows:
The dynamic part of the code is written in Java, not in Visual Basic or the Microsoft-specific language. Hence, it is powerful and easier to use.

It is portable to other operating systems and Non-Microsoft Web servers.

Posted Date:- 2021-08-18 11:03:58

What JSP lifecycle methods can I override?

You cannot override the _jspService() method within a JSP page. You can however, override the jspInit() and
jspDestroy() methods within a JSP page. jspInit() can be useful for allocating resources like database
connections, network connections, and so forth for the JSP page. It is good programming practice to free any
allocated resources within jspDestroy().
The jspInit() and jspDestroy() methods are each executed just once during the lifecycle of a JSP page and are
typically declared as JSP declarations.

Posted Date:- 2021-08-18 11:02:22

How do you include the static files in JSP?

JSP includes directives that are used to deploy static files in JSP. In this way, the inclusion process is performed only once as the resources are included, but before that, the URL must be given for file.

Posted Date:- 2021-08-18 11:01:11

What are the tags available in JSTL?

There are five tags available in JSTL

1. Core tags
2. Function tags
3. SQL tags
4. XML tags
5. Internationalization tags

Posted Date:- 2021-08-18 11:00:26

What is JSTL?

It is a JSP library that has predefined tags and soothes the process of developing JavaServlet Page.

Posted Date:- 2021-08-18 10:59:00

What is Object Cloning?

The object cloning is a process of creating an exact copy of the existing object. The clone() method of Object class is used to create the clone an existing object. The class, whose object the user tries to clone is expected to implement the java.lang.Cloneable interface. If it does not implement the Cloneable interface, then the clone() method generates the CloneNotSupportedException.
1. protected Object clone() throws CloneNotSupportedException

Posted Date:- 2021-08-18 10:58:31

Explain Client-Side and Server-Side Validation.

The Client-Side validation is done using JavaScript. The validation takes place within the browser. Javascript is used to submit the data in the form when the validation is successful. Validation errors do not require any extra network trip because the form cannot be submitted if there are any errors.

Posted Date:- 2021-08-18 10:57:19

Can a Constructor be used in place of init() method to initialize a servlet?

Yes, We can use a constructor in place of init() method. 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. However, servlet containers still call an only no-arg constructor. So there is no access to servletContext or servletConfig.

Posted Date:- 2021-08-18 10:45:31

How can we stop errors on Display in a JSP Page?

We can stop errors in display in a JSP Page by setting up an “ErrorPage” attribute of the PAGE directory to the name of the error page in the JSP page, and then in the error JSP page set “isErrorpage=”TRUE”.

Posted Date:- 2021-08-18 10:44:59

How to include static files in a JSP?

Static pages can be included in a JSP using the include directive. This way the inclusion is performed in the translation phase once. Note that a relative URL must be supplied for file attribute. Although static resources may be included, it is not preferred as each request requires inclusion.

Posted Date:- 2021-08-18 10:44:29

Mention the Implicit Objects in a JSP.

The Web Container creates certain objects that include the information related to a particular Request, Application or a Page. These Objects are called as Implicit Objects. The Implicit Objects in the JSP are as follows:

Posted Date:- 2021-08-18 10:35:40

How can a servlet refresh automatically if some new data has entered the database?

You can use a client-side Refresh or Server Push.

Posted Date:- 2021-08-18 10:35:09

Is JSP technology extensible?

YES. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated
in tag libraries.

Posted Date:- 2021-08-18 10:30:21

Why are JSP pages the preferred API for creating a web-based client program?

JSP pages the preferred API for creating a web-based client program because no plug-ins or security policy files are needed on the client systems(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.

Posted Date:- 2021-08-18 10:29:48

What are the implicit objects?

Implicit objects are objects that are created by the web container and contain information related to a particular
request, page, or application. They are:
--request
--response
Saikat Banerjee Page 2
--pageContext
--session
--application
--out
--config
--page
--exception

Posted Date:- 2021-08-18 10:28:36

Mention the three important tags used in the development of JSP Bean.

The Three tags used in the JSP Bean development are as follows:
jsp:useBean
jsp:setProperty
jsp:getProperty

Posted Date:- 2021-08-18 10:27:15

How are Custom Tags in JSP created?

Custom Tags in JSP are created using the following steps.
1.Creating the Tag Handler Class
2.Creating the TLD File
3.Creating the JSP File
Creating the Tag Handler Class:
To create a Tag Handler Class, we need to inherit the TagSupport Class and then override doStartTag() method. To write the data for JSP, we need to use the JspWriter class. The PageContext class provides getOut() method which returns the instance of the JspWriter class. Later, the TagSupport class provides an instance of pageContext by default.
Creating the TLD File:
TLD stands for Tag Library Descriptor file. It contains the information related to the tag and Tag Hander classes. It must be held inside the WEB-INF directory.
Creating the JSP File:
We will be specifying the path of the TLD file directly. It is recommended to use the URI name instead of full a path of the TLD file. It uses taglib directive to use the tags defined in the TLD file.

Posted Date:- 2021-08-18 10:24:48

Name the consisting blocks of JSP literals.

1. Boolean
2. Integer
3. Floating point
4. Null
5. String

Posted Date:- 2021-08-18 10:23:26

How to forward a request to JSP servlet?

To forward the JSP servlet request, one can use the “forward” tag before that one needs to send the URL pattern of the servlet.

Posted Date:- 2021-08-18 10:22:34

Name a few attributes under the JSP page directive.

Below is the list of few attributes of the JSP page directive briefly explained.
1. Import attribute:- Used to guide containers to import java classes and interfaces and produce servlet side by side. It is also one of the most used attributes.
2. Extends attribute:- It defines the superclass produced by servlet code, and it can be used when one has expanded HttpServlet.

Posted Date:- 2021-08-18 10:20:01

What do you understand by the JSP page directive?

JSP page directives apply to the whole page and offer a number of attributes in one single page. It is also possible to have numerous page directives applied to a single JSP page.

Posted Date:- 2021-08-18 10:19:01

How are Custom Tags in JSP created?

Custom Tags in JSP are created using the following steps.
1. Creating the Tag Handler Class
2. Creating the TLD File
3. Creating the JSP File

Posted Date:- 2021-08-18 10:18:18

What is implicit object and how many implicit objects do we have in JSP?

The objects which are created or given by the container to implement our jsp logic are called Implicit Objects.
We have 9 implicit objects.
1. config
2. session
3. application(context)
4. pageContext
5. out
6. page
7. exception
8. request
9. response

Posted Date:- 2021-08-18 10:16:52

What is the major difference between ServletContext and PageContext?

The major difference between ServletContect and PageContext is, the ServletContext is designed to provide information about the Container and on the other hand, the PageContext is designed to provide information about the Request.

Posted Date:- 2021-08-18 10:10:30

What are the Literals used in JSP?

The Literals used in JSP are as follows:
Null
Boolean
String
Integer
Float

Posted Date:- 2021-08-18 10:09:15

What are JSP implicit objects? Define briefly.

The JSP implicit objects are established by the servlet while converting JSP to the servlet container. Nine JSP implicit objects can be used in a JSP page directly. Two implicit items are part of the _jspService() method argument. Seven out of nine implicit objects are asserted as a local variable of _jspService().

Posted Date:- 2021-08-18 10:07:53

Speaking of JSP scripting elements, what do you understand by JSP declarations?

As the name hints, the JSP declarations are chiefly utilized to declare methods and class variables on a JSP page. At the same time, it is significant to keep in mind the exceptions to the application of the same. Declarations are not included in the service method when a JSP is translated to a servlet.

Posted Date:- 2021-08-18 10:06:41

What is a scriptlet tag and its usage?

It is useful for writing the code within the _jspService(.........,.........). It is useful for declaring local variables, final variables, method calling statements, doing operations (logic).We can write one or more statements and every statement ended with semicolon.

Posted Date:- 2021-08-18 10:05:39

What is a declaration tag and its usage?

This tag is useful writing code/programming elements at class level.
The programming elements may be blocks, constructors, variables, methods.
The code is always added to our class outside of the _jspService(-,-).
We can write multiple statements within the single declaration tag.
Every statement should be ended with semicolon.
Syntax: <%! ————– %>

Posted Date:- 2021-08-18 10:04:16

What is include directive and include action?

Include directive and include action, as the name suggests, is the method used to include the result of some other page to the required destination.

Posted Date:- 2021-08-18 10:02:16

What are the advantages of JSP over ASP?

The dynamic part of JSP is written in java and hence proves to be easier and powerful. It can effortlessly port itself to any operating system.

Posted Date:- 2021-08-18 10:01:58

How many types of comments are we using in JSP?

There are three types of comments we can use in JSP.
1. HTML comment <!– comment text –>
This tag is not ignored by the JSP container, this tag will be placed into Page Implementation class (PIC), handover to browser by Servlet container, but browser will ignores.
2. JSP comment <%– comment text –%>
This tag is ignored by the Jsp Container
3. Java comment: If we are writing java comments outside of html comment and jsp comment these comments will be treated as html code.
If we are writing java comments in declarative and scriptlet tag these comments not ignored by the jsp container these comments are placed into PIC in translation phase, but in compilation jsp container ignores.

Posted Date:- 2021-08-18 10:01:35

How many tags do we have in JSP?

We have 5 types of tags in JSP.
1. Scripting tags
2. Directive tags.
3. Standard action tags
4. Custom action tags
5. JSTL

Posted Date:- 2021-08-18 10:00:41

Why do developers prefer to write JSP text files?

The JSP text files combine all the available files of HTML, XML code, and elements and the previously rooted java code.

Posted Date:- 2021-08-18 09:59:22

What is the JavaServer Page component?

The JavaServer page is the java servlet that acts as the user interface for java based applications.

Posted Date:- 2021-08-18 09:58:58

How do the JSP tags start and end?

The JSP tags generally start with <% and end with %>

Posted Date:- 2021-08-18 09:58:37

What is JSP?

JavaServer Pages is a technology employed to develop web pages that aid dynamic content. It is a server-side programming language exploited by developers to insert java code in HTML files.

Posted Date:- 2021-08-18 09:58:17

Search
R4R Team
R4R provides JSP Freshers questions and answers (JSP Interview Questions and Answers) .The questions on R4R.in website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,JSP fresher interview question ,JSP Freshers & Experienced Interview Questions and Answers,JSP Objetive choice questions and answers,JSP Multiple choice questions and answers,JSP objective, JSP questions , JSP answers,JSP MCQs questions and answers R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for JSP fresher interview questions ,JSP Experienced interview questions,JSP fresher interview questions and answers ,JSP Experienced interview questions and answers,tricky JSP queries for interview pdf,complex JSP for practice with answers,JSP for practice with answers You can search job and get offer latters by studing r4r.in .learn in easy ways .