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

Why do you use JSP?

JSPs are used in order to develop dynamic web content, where input from visitor will be considered as a request, and model view controller as a web framework where the presentation layer is Java Server Pages (JSP) – Java code inside HTML/CSS/JavaScript code, business logic written in the middle layer, Controller will have Java classes, and Model has backend DAO(i.e. Hibernate) to access the database.

Posted Date:- 2021-08-18 12:42:02

Can constructor be used instead of init(), to initialize servlet?

Yes, it is possible. 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. Today, however, servlet containers still call only no-arg constructor. So there is no access to servletContext or servletConfig.

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

How to restrict page errors display in a JSP page?

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.

Posted Date:- 2021-08-18 12:40:18

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

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

Posted Date:- 2021-08-18 12:39:06

What are context initialization parameters?

Context initialization parameters are specified by the <context-param> in the web.xml file, these are initialization parameter for the whole application and not specific to any servlet or JSP.

Posted Date:- 2021-08-18 12:38:32

How is JSP used in the MVC model?

JSP is usually used for presentation in the MVC pattern (Model View Controller ) i.e. it plays the role of the view. The controller deals with calling the model and the business classes which in turn get the data, this data is then presented to the JSP for rendering on to the client.

Posted Date:- 2021-08-18 12:37:56

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

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.

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

How can we handle the exceptions in JSP ?

There are two ways to perform exception handling, one is by the errorPage element of page directive, and second is by the error-page element of web.xml file.

Posted Date:- 2021-08-18 12:36:34

How can I implement a thread-safe JSP page? What are the advantages and Disadvantages of using it?

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 12:35:57

What is difference between hide comment and output comment?

The jsp comment is called hide comment whereas html comment is called output comment. If user views the source of the page, the jsp comment will not be shown whereas html comment will be shown

Posted Date:- 2021-08-18 12:35:16

What do you meant by the output comment in the JSP context?

An output comment is the part of the generated HTML of the JSP page. On the client-side, you can see the comment from the page source in the Web browser.
JSP output comment syntax.

<!– comment [ <%= expression %> ] –>
e.g.
<!– Output comment is a part of the HTML shown to client. –>

Following text would appear in the page source in the web browser.
<!– Output comment is a part of the HTML shown to client. — January 24, 2004 –>

Posted Date:- 2021-08-18 12:32:29

How to restrict the caching of the JSP/servlet output on the client side?

Use the relevant HTTP header attributes to block the caching of JSP page output by the browser.

Posted Date:- 2021-08-18 12:30:57

What is the right way to declare a method in a JSP page?

You can declare a method in a JSP page as a declaration.

Later you can call this method from any other methods of the JSP expressions or scriptlets.

For your note, there is no direct access allowed to the JSP implicit objects (request, response, and session, etc.). But you can pass the JSP variables as parameters to the method which is declared

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

How to disable scripting?

Scripting can be easily disabled by setting scripting-invalid element of the deployment descriptor to true. It is a sub-element of property group. Its can be false as well.

Posted Date:- 2021-08-18 12:27:26

Define the scopes available with the <jsp: useBean>?

Page Scope: Tells the bean object is available for the entire JSP page without any external access.
Request Scope: Signifies the object can link with a particular request and persist till the time request lasts.
Session Scope: States that the bean object is available throughout the session.
Application Scope: Specifies the bean object is available throughout the entire Web application discarding any external access.

Posted Date:- 2021-08-18 12:26:56

What is div in JSP?

A <div> tag is used to describe a specific section on the web page. The tag can also be used as a container to group two or more elements and style them. For JSP, the tag can be used to display specific data or text on the web page.

Posted Date:- 2021-08-18 12:23:02

How can Automatic creation of session be prevented in a JSP page?

JSP page automatically create sessions for requests. By typing the following, it can be avoided.

<%@ page session=”false” %>

Posted Date:- 2021-08-18 12:20:39

What is a JSP Custom Tag and what are the components does it have?

It’s a user-defined JSP element which can do operations that the standard tags like Action Tags or JSTL tags are not able to perform
You can create JSP Custom Tags with the below items

1.JSP Custom Tag Handler,
2.Creating Tag Library Descriptor (TLD) File, and
3.Deployment Descriptor Configuration (DDC) for TLD.

Posted Date:- 2021-08-18 12:18:34

What do you know about writing custom jsp tags?

JSP allows you to create your own tags with the necessary functionality. We can add a tag library to a JSP page using the namespace specification. To create your tag, we can use the following components:
JSP Custom Tag Handler
Creating a Tag Library Descriptor (TLD) File
Deployment Descriptor configuration for TLD

Posted Date:- 2021-08-18 12:16:35

Explain handling of runtime exceptions.

Errorpage attribute is used to uncatch the run-time exceptions forwarded automatically to an error processing page.

It redirects the browser to JSP page error.jsp if any uncaught exception is faces during request handling. It is an error processing page.

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

How many types of tags exist in the JSTL library?

Looking at the JSTL functions, there are five types of JSTL tags that we should know.
Core Tags – Enable support for loops, conditional logic, exception handling, the ability of forwarding/redirecting response, etc.
Formatting/Localization Tags – add features like the manipulation of date/number format and enabling i18n support with the help of locales and resource packages.
JSTL Functions Tags – JSTL has a set of features that allow String handling features like concatenation, split operations, etc.
XML Tags – XML tags enable reading/writing of XML documents. Some of the key features are XML parsing, transforming XML data and evaluation of XPath expressions.
SQL Tags – JSTL brings some unique tags that cater the integration of JSP pages with databases like MySql, Oracle, etc.

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

How can you pass information from one jsp to included jsp ?

This JSP interview question is a little tricky and fact based. Using < Jsp: param> tag we can pass parameter from main jsp to included jsp page
Example:
<jsp:include page="newbid.jsp" flush="true">
<jsp:param name="price" value="123.7"/>
<jsp:param name="quantity" value="4"/>

Posted Date:- 2021-08-18 12:09:01

Is it possible for one JSP to extend another java class if yes how?

Yes it is possible we can extends another JSP using this <%@ include page extends="classname" %> it’s a perfectly correct because when JSP is converted to servlet its implements javax.servlet.jsp.HttpJspPage interface, so for jsp page its possible to extend another java class . This question can be tricky if you don’t know some basic fact J, though it's not advisable to write java code in jsp instead it's better to use expression language and tag library.

Posted Date:- 2021-08-18 12:07:33

What are the difference between JspWriter and Servlet PrintWriter?

JSP PrintWriter is object directly responsible for writing the content in response, whereas JspWriter uses the PrintWriter object behind the scene while offering buffer support. After the buffer support is flushed or full, JspWriter uses the object in PrintWriter to write the content into a response.

Posted Date:- 2021-08-18 12:06:05

What are the difference between ServletContext and PageContext?

In JSP, the ServletContext shares information about the container in which the servlet is running in. This can be set up in the web application descriptor. There can be only one v ServletContext per web application. Compared to this, the PageContext gives the servlet information about the request that it is currently managing and contains information about the request, the response object, the session, and also a reference to the ServletContext of the web application.

Posted Date:- 2021-08-18 12:05:19

How we can include the result of another page in JSP?

So many mechanisms are available through which the results of another page can be included in JSP.
There of primary mechanisms used by developers are
Include directive
jsp:include element
Codas and preludes

Posted Date:- 2021-08-18 12:04:34

What do you know about jsp tags? Explain how you understand the Action tag and JSP Action Elements.

JSP elements or action tags provide useful functionality for working with Java Bean, embedding resources, forwarding a query, and creating dynamic XML elements. The jsp action elements always start with the jsp: entry and we can use them right inside the JSP page without the need to connect libraries or other settings.

Posted Date:- 2021-08-18 12:03:17

Why is it not recommended to use script elements in jsp?

JSP pages are mainly used for displaying the view, and all business logic and models must be implemented in servlets or classes of models. We must pass parameters to the JSP page through attributes and then use them to create an HTML response on the JSP page. Most JSPs contain HTML code and, in order to help designers understand the code of a JSP page and develop them, provide action, JSP EL, JSP Standart Tag Library elements. These elements must be used instead of scriptlets to create a bridge between JSP HTML and JSP java parts.

Posted Date:- 2021-08-18 12:02:21

How to configure init parameters for JSP?

We can set initialization parameters for a JSP in the same way as servlets in a web.xml file. We need to configure the init JSP parameters with servlet and servlet-mapping elements. The only difference is the location of the JSP page.

Posted Date:- 2021-08-18 12:01:55

What do you know about PageContext and what are the advantages of using it?

The implicit JSP object pageContext is an instance of the implementation of the abstract javax.servlet.jsp.PageContext class . We can use the pageContext object to get and set attributes with different scopes and to forward requests to another resource. This object also has a link to another implicit object. This is the only object that is represented in JSP implicit objects and JSP EL implicit objects.

Posted Date:- 2021-08-18 12:01:32

Why are implicit objects not available in a regular JSP page?

The implicit JSP exception object is not available in regular JSP pages and is used on JSP error pages only to catch the exception thrown by the JSP page and then provide any useful information to the client.

Posted Date:- 2021-08-18 12:01:06

Can you explain the MVC model and the use of JSP in it?

Model View Controller or MVC is a design pattern that separates data, business logic, and presentation logic. Model is the state of application representing business logic, Controller is a middle portion of view and model contains data, whereas View is a user interface or presentation layer.
A user sends the request from the browser present on the client machine, via the user interface or presentation layer of the JSP page. JSP page connects JavaBean which contains business logic and exchanges requests and response using the HTTP protocol. The response is sent back to the browser that contains status information and response content.

Posted Date:- 2021-08-18 11:55:40

What are the advantages of JSP?

It allows tag-based programming
Suitable for both Java and non-Java programmers
Allows developers to use separate presentation logic
Highly increases readability of code because of tags
Easy to learn and apply

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

What are features of JSP that make it an essential web-based technology?

The features are listed below:
1.Create interactive websites.
2Makes it easy-to-read user input data and display server response.
3.Use of implicit objects into the web page directly.
4.Use of Java code into HTML pages through JSP.
5.Makes database connectivity simple.
6.Visitors can be tracked using Session, Application, or Cookies on the JSP page.
7.Easy to learn and code.

Posted Date:- 2021-08-18 11:50:30

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 11:46:10

In the Servlet 2.4 specification SingleThreadModel has been deprecated, why?

Because it is not practical to have such model. Whether you set isThreadSafe to true or false, you should take
care of concurrent client requests to the JSP page by synchronizing access to any shared objects defined at the
page level.

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

How many JSP scripting elements are there and what are they?

There are three scripting language elements: declarations, scriptlets, expressions.

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

What Class.forName will do while loading drivers?

It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a
driver, it is available for making a connection with a DBMS.

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

What do you understand by the term scriptlet?

So far as a scriptlet is concerned, it may be defined as one that contains fundamental Java code that is implemented every time a JSP is called. As we mentioned before, in the case of the translation of the JSP into a servlet, it is essentially the scriptlet that goes into the so called service method in order to bring about the same. It is essentially executed at the request processing time by the container.

Posted Date:- 2021-08-18 11:43:12

Can you tell us how could you disable a script?

By fixing the scripting invalid element of the descriptor deployment to the true condition, you can induce disability of a script. As is well known, the validation can either be true or false.

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

Can you highlight the functionality of the include function in brief?

So far as the include function is concerned, it is chiefly used for the purpose of inclusion of a response from a servlet or a JSP page to the current page. However, it is important not to confuse with the include directive which includes a resource at translation time, unlike the include function which does it at request processing time.

Posted Date:- 2021-08-18 11:41:31

Can constructor be used instead of init(), to initialize servlet?

Yes, it is possible. 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. Today, however, servlet containers still call only no-arg constructor. So there is no access to servletContext or servletConfig.

Posted Date:- 2021-08-18 11:40:52

What are the advantages of JSP over Servlet?

JSP is a server-side construct to simplify the dynamic generation of the HTML content. One of its advantages is that JSP is document-centric. While the Servlets purely behave like the programs. A JSP Page can consist of Java code fragments that can instantiate and invokes the methods of Java classes. All of this occur inside an HTML template file which is mainly used to produce dynamic content. However, some of the JSP functionality can be achieved at the client-end using JavaScript. The power of JSP is that it is server-based and provides a framework for Web application.

Advantages of JSP.
JSP represents an HTML page embed with Java code.
JSP is cross-platform technology.
JSP can create database-driven Web applications.
JSP enables Server-side programming abilities.

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

How to restrict page errors display in a JSP page?

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.

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

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

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

Posted Date:- 2021-08-18 11:38:48

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

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 in translated to a Java servlet, and then executed. Only HTML code is given as output.

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

How can multiple submits due to refresh button clicks be prevented?

Using a Post/Redirect/Get or a PRG pattern, this problem can be solved.
1) A form filled by the user is submitted to the server using POST or GET method. The state in the database and business model are updated.

2) A redirect response is used to reply by the servlet for a view page.

3) A view is loaded by the browser using the GET command and no user data is sent. This is safe from multiple submits as it is a separate JSP page.

Posted Date:- 2021-08-18 11:36:44

What do you understand by the term JSP directives?

JSP directives are nothing but fundamental messages from the JSP page to the JSP container in order to control the processing of a page. Generally speaking, JSP directives are essentially meant for such purposes as a class declaration and method implementation among other things. However, it is important to keep in mind that JSP directives do not trot out any output on the client side.

Posted Date:- 2021-08-18 11:34: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 experienced 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 .