YouTube Icon

Interview Questions.

Top 50 Jsp Interview Questions - Jul 26, 2022

fluid

Top 50 Jsp Interview Questions

Q1. How Is Jsp Used In The Mvc Model

JSP is commonly used for presentation in the MVC sample (Model View Controller ) i.E. It performs the position of the view. The controller deals with calling the model and the commercial enterprise training which in turn get the records, this statistics is then offered to the JSP for rendering on to the client.

Q2. What Is A Scriptlet?

A scriptlet can comprise any range of language statements, variable or method declarations, or expressions which can be valid within the web page scripting language.Within scriptlet tags, you can

1.Declare variables or methods to apply later within the record (see additionally Declaration).

2.Write expressions valid within the page scripting language (see also Expression).

Three.Use any of the JSP implicit objects or any object declared with a <jsp:useBean> tag. You should write plain text, HTML-encoded textual content, or different JSP tags out of doors the scriptlet.

Scriptlets are finished at request time, when the JSP engine methods the purchaser request. If the scriptlet produces output, the output is saved in the out item, from which you could show it.

Q3. What Is The Difference Between Directive Include And Jsp Include?

Encompass directive :

The record receives included at the compile time.

It is static in nature.Output comes with jsp page however complete record contains is included in jsp then compilation is completed.

Action tag :

The record gets included at the run time. This is quicker.

It's far dynamic in nature.Output of yhe file willbe blanketed in the jsp file.

Q4. How Does Jsp Handle Runtime Exceptions?

Using errorPage attribute of web page directive and additionally we need to specify isErrorPage=proper if the modern page is meant to URL redirecting of a JSP.

Q5. What Are The Steps Required In Adding A Jsp Tag Libraries?

Create a TLD report and configure the desired magnificence Information.

Create the Java Implementation Source extending the JSP Tag Lib Class (TagSupport).

Compile and package it as loosed magnificence document or as a jar underneath lib folder in Web Archive File for Class loading.

Place the TLD report underneath the WEB-INF folder.

Add reference to the tag library in the web.Xml record.

Q6. Explain The Life-cycle Mehtods In Jsp?

The generated servlet class for a JSP page implements the HttpJspPage interface of the javax.Servlet.Jsp bundle. Hte HttpJspPage interface extends the JspPage interface which inturn extends the Servlet interface of the javax.Servlet package. The generated servlet magnificence therefore implements all of the strategies of the those 3 interfaces. The JspPage interface broadcasts best two mehtods - jspInit() and jspDestroy() that should be implemented through all JSP web page regardless of the consumer-server protocol. However the JSP specification has supplied the HttpJspPage interfaec specially for the JSp pages serving HTTP requests.

This interface proclaims one method_jspService(). 

The jspInit()- The field calls the jspInit() to initialize te servlet example.It is referred to as earlier than another approach, and is referred to as handiest as soon as for a servlet example.

The _jspservice()- The container calls the _jspservice() for every request, passing it the request and the reaction items.

The jspDestroy()- The container calls this whilst it decides take the instance out of service. It is the final approach called n the servlet example.

Q7. How Cookies Is Deleted In Jsp?

There are  methods with the aid of which the cookies may be deleted in JSP. Firstly, by means of placing the setMaxAge() of the cookie elegance to 0. And secondly through setting a timer inside the header report this is response. SetHeader(expires Mention the time attribute), with a purpose to delete the cookies after that prescribed time.

Q8. In The Servlet 2.Four Specification Singlethreadmodel Has Been Deprecated, Why?

Because it isn't practical to have such version. Whether you place isThreadSafe to true or false, you have to contend with concurrent customer requests to the JSP page with the aid of synchronizing get right of entry to to any shared gadgets defined at the page level.

Q9. What Are The Jsp Standard Actions?

• The JSP widespread moves have an effect on the overall runtime behavior of a JSP page and also the reaction despatched back to the patron.

• They may be used to consist of a document at the request time, to discover or instantiate a JavaBean, to forward a request to a brand new page, to generate a browser-precise code, and many others.

• Ex: consist of, ahead, useBean,etc.

Q10. Outline The Difference Between Java Server Page Forward And Servlet Forward Method?

The most effective minor difference among both the techniques is that Java Server web page ahead technique can’t forward to any other JSP web page in some other net application or box while servlet ahead approach can achieve this.

Q11. What Are The Lifecycle Phases Of A Jsp?

JSP page looks as if a HTML page but is a servlet. When provided with JSP page the JSP engine does the subsequent 7 phases.

1. Page trlation: -web page is parsed, and a java record which is a servlet is created.

2. Page compilation: page is compiled into a category report

three. Page loading : This class document is loaded.

Four. Create an example :- Instance of servlet is created

five. JspInit() method is called

6. _jspService is called to address provider calls

7. _jspDestroy is called to spoil it when the servlet isn't required.

Q12. Difference Between Get And Post?

In GET your whole form submission can be encapsulated in one URL, like a link. Query duration is confined to 255 characters, no longer cozy, faster, quick and smooth. The information is submitted as part of URL.

In POST records is submitted inner frame of the HTTP request. The data isn't always visible on the URL and it is extra secure.

Q13. Why Are Jsp Pages The Preferred Api For Creating A Web-based totally Client Program?

Because no plug-ins or safety coverage files are wanted on the client structures(applet does). Also, JSP pages allow purifier and greater module software design because they provide a way to separate packages programming from web page layout. This me personnel concerned in net web page design do now not want to understand Java programming language syntax to do their jobs.

Q14. Differentiate Between Pagecontext.Consist of And Jsp:include?

The <jsp:include> trendy movement and thepageContext.Include() approach are both used to include sources at runtime. However, thepageContext.Consist of() method constantly flushes the output of the cutting-edge web page before along with the alternative additives, while<jsp:include> flushes the output of the contemporary page handiest if the price = of flush is explicitly set to true as follows:

<jsp:include page="/index.Jsp" flush="true"/>

Q15. How Do You Delete A Cookie Within A Jsp?

Cookie mycook = new Cookie("name","fee");

response.AddCookie(mycook);

Cookie killmycook = new Cookie("mycook","value");

killmycook.SetMaxAge(0);

killmycook.SetPath("/");

killmycook.AddCookie(killmycook);

Q16. What Is Jsp Page?

A JSP page is a textual content-primarily based report that incorporates two styles of text: static template data, which can be expressed in any textual content-based totally layout along with HTML, SVG, WML, and XML, and JSP factors, which assemble dynamic content material.

Q17. What Is Jsp? Describe Its Concept?

JSP is a era that mixes HTML/XML markup languages and elements of Java programming Language to return dynamic content to the Web consumer, It is commonly used to address Presentation common sense of an internet software, even though it could have enterprise logic.

Q18. What Is A Trlation Unit?

JSP web page can consist of the contents of different HTML pages or different JSP files. This is carried out via the use of the consist of directive. When the JSP engine is offered with one of these JSP web page it is converted to at least one servlet class and this is known as a trlation unit, Things to recollect in a trlation unit is that page directives affect the complete unit, one variable statement cannot occur inside the equal unit extra than as soon as, the same old action jsp:useBean can not claim the same bean two times in a single unit.

Q19. Can We Override The Jspinit(), _jspservice() And Jspdestroy() Methods?

We can override jspinit() and jspDestroy() methods but no longer _jspService().

Q20. What Is The Jsp:plugin Action ?

This action lets you insert the browser-specific OBJECT or EMBED detail needed to specify that the browser run an applet using the Java plugin.

Q21. What Is The Standard Action?

The <jsp:include> popular action allows the cutting-edge JSP web page to consist of a static or a dynamic resource at runtime. In contrast to the consist of directive, the consist of movement is used for resources that change often. The resource to be included need to be within the equal context.The syntax of the <jsp:include> wellknown action is as follows:

<jsp:include page="targetPage" flush="true"/> 

Here, targetPage is the web page to be protected in the cutting-edge JSP.

Q22. What Is Jsp?

Let's take into account the wer to that from  unique views: that of an HTML clothier and that of a Java programmer.

If you're an HTML fashion designer, you may take a look at JSP technology as extending HTML to provide you with the ability to seamlessly embed snippets of Java code inside your HTML pages. These bits of Java code generate dynamic content, that is embedded within the different HTML/XML content you writer. Even better, JSP generation affords the me by way of which programmers can create new HTML/XML tags and JavaBe components, which provide new capabilities for HTML designers without those designers desiring to discover ways to software.

Note: A common false impression is that Java code embedded in a JSP web page is trmitted with the HTML and completed via the person agent (which include a browser). This isn't always the case. A JSP page is trlated into a Java servlet and accomplished on the server. JSP statements embedded within the JSP page turn out to be part of the servlet generated from the JSP web page. The ensuing servlet is finished at the server. It is in no way seen to the consumer agent. If you're a Java programmer, you could study JSP generation as a brand new, higher-level me to writing servlets. Instead of at once writing servlet training after which emitting HTML out of your servlets, you write HTML pages with Java code embedded in them. The JSP surroundings takes your page and dynamically compiles it. Whenever a person agent requests that web page from the Web server, the servlet that turned into generated from your JSP code is done, and the consequences are again to the user.

Q23. What Are Jsp Declarations?

As the call implies, JSP declarations are used to claim elegance variables and techniques in a JSP page. They are initialized while the magnificence is initialized. Anything defined in a announcement is available for the whole JSP web page. A statement block is enclosed between the <%! And %> tags. A statement isn't always included in theservice() approach when a JSP is trlated to a servlet.

Q24. What Are The Implicit Objects?

Implicit items are objects which can be created with the aid of the internet container and comprise information related to a selected request, web page, or application. They are:

--request

--response

--pageContext

--consultation

--application

--out

--config

--web page

--exception

Q25. The Code In A Finally Clause Will Never Fail To Execute, Right?

Using System.Exit(1); in try block will not permit subsequently code to execute.

Q26. How Can My Application Get To Know When A Httpsession Is Removed?

Define a Class HttpSessionNotifier which implements HttpSessionBindingListener and put in force the functionality what you need in valueUnbound() method.

Create an example of that elegance and positioned that instance in HttpSession.

Q27. What Are Stored Procedures? How Is It Useful?

A saved technique is a fixed of statements/instructions which live in the database. The stored manner is pre-compiled and saves the database the effort of parsing and compiling sq. Statements each time a question is run. Each database has its personal saved system language, typically a version of C with a SQL preproceesor. Newer versions of db’s support writing stored strategies in Java and Perl too. Before the appearance of three-tier/n-tier architecture it become pretty common for stored procs to implement the commercial enterprise logic( A lot of systems nonetheless do it). The biggest gain is of direction speed. Also sure type of information manipulations aren't finished in SQL. Stored procs provide a mechanism to do these manipulations. Stored procs are also useful while you need to do Batch updates/exports/houseKeeping kind of stuff at the db. The overhead of a JDBC Connection can be large in these instances.

Q28. What Class.Forname Will Do While Loading Drivers?

It is used to create an example of a driver and register it with the DriverManager. When you've got loaded a driving force, it is available for creating a connection with a DBMS.

Q29. What Is Declaration In Jsp?

In Java Server pages Declaration is used to declare and outline variables and methods that may be used in the Java Server Pages. The variable which is asserted is initialized as soon as and it hold its value for each subsequent client request.

Q30. How To Override The Lifecycle Methods Of Jsp?

Lifecycle technique jspService() can't be overridden inside a JSP page however methods like jspInit() and jspDestroy() can be overridden inside a JSP web page. Method jspInit() is used for allocating useful resource whilst method jspDestroy() is used to loose allocated resource. But it need to be kept in thoughts that during the lifecycle of a Java Server Page each the approach jsplnit() and jspDestroy() is carried out as soon as and are declared as JSP declarations.

Q31. Can I Stop Jsp Execution While In The Midst Of Processing A Request?

Yes. Preemptive termination of request processing on an error circumstance is a great manner to maximise the throughput of a excessive-quantity JSP engine. The trick (assuming Java is your scripting language) is to apply the return assertion when you want to terminate in addition processing.

Q32. Can You Make Use Of A Servletoutputstream Object From Within A Jsp Page?

No. You are supposed to make use of most effective a JSPWriter object (given to you within the shape of the implicit item out) for replying to clients.

A JSPWriter can be viewed as a buffered version of the circulate object back via reaction.GetWriter(), despite the fact that from an implementational attitude, it isn't.

Q33. What Are The Implicit Objects In Jsp?

There are all general 9 implicit items in JSP. Application interface refers to the net utility’s interface whereas Session interface refers to the user’s consultation. Request interface refers back to the page that is currently asked while Response interface refers to the reaction that is currently made by the user. Config interface refers to the servlet configuration. Class like out, web page, page Context and exception refers to the output movement of the page, servlet instance of the page, surroundings of the web page, error dealing with respectively.

Q34. What Is The Page Directive Is Used To Prevent A Jsp Page From Automatically Creating A Session:

<%@ page session="false">

Q35. What Are Context Initialization Parameters

Context initialization parameters are special by means of the within the web.Xml report, those are initialization parameter for the whole utility and not particular to any servlet or JSP.

Q36. How Do You Connect To The Database From Jsp?

A Connection to a database may be mounted from a jsp web page with the aid of writing the code to set up a connection the usage of a jsp scriptlets.

Further then you can use the resultset item "res" to examine statistics in the following way.

Q37. Can We Use The Constructor, Instead Of Init(), To Initialize Servlet?

Yes , of course you could use the constructor in place of init(). There’s nothing to forestall you. But you shouldn’t. The unique cause for init() become that historical variations of Java couldn’t dynamically invoke constructors with arguments, so there was no way to provide the constructur a ServletConfig. That not applies, however servlet bins still will most effective name your no-arg constructor. So you won’t have get entry to to a ServletConfig or Servlet Context.

Q38. What Are The Attributes Of Page Directive?

There are thirteen attributes defined for a page directive of which the vital attributes are as follows:

• import: It specifies the programs which are to be imported.

• consultation: It specifies whether a consultation records is available to the JSP page.

• contentType: It lets in a user to set the content material-kind for a web page.

• isELIgnored: It specifies whether or not the EL expressions are omitted while a JSP is trlated to a servlet.

Q39. What Are The Standard Actions Available In Jsp?

The fashionable moves to be had in JSP are as follows:

<jsp:include>:It consists of a reaction from a servlet or a JSP page into the modern page.It differs from an encompass directive in that it includes a aid at request processing time, while the encompass directive consists of a resource at trlation time.

<jsp:forward>:It forwards a response from a servlet or a JSP web page to any other web page.

<jsp:useBean>:It makes a JavaBean to be had to a page and instantiates the bean.

<jsp:setProperty>:It units the properties for a JavaBean.

<jsp:getProperty>:It receives the value of a belongings from a JavaBean element and adds it to the reaction.

<jsp:param>:It is used together with <jsp:forward>;, <jsp:, or plugin>; to add a parameter to a request. These parameters are provided using the call-value pairs.

<jsp:plugin>:It is used to consist of a Java applet or a JavaBean in the cutting-edge JSP web page.
 

Q40. What Are Advantages Of Jsp

on every occasion there's a trade within the code, we dont should recompile the jsp. It robotically does the compilation. By means of the usage of custom tags and tag libraries the length of the java code is decreased.

Q41. How To Pass Information From Jsp To Included Jsp?

Using <%jsp:param> tag.

Q42. What Are Scripting Elements?

JSP scripting elements permit you to insert Java code into the servlet on the way to be generated from the modern JSP page. There are three forms:

Expressionsof the shape <%= expression %> that are evaluated and inserted into the output,

Scriptletsof the shape <% code %> which can be inserted into the servlet's service technique,

Declarationsof the form <%! Code %> that are inserted into the frame of the servlet magnificence, outdoor of any existing methods.

Q43. Is There A Way To Reference The "this" Variable Within A Jsp Page?

Yes, there may be. Under JSP 1.0, the web page implicit object is equal to "this", and returns a connection with the Servlet generated by the JSP page.

Q44. What Is A Servlet ?

Servlet is a java program that runs interior an internet container.

Q45. What Are Custom Tags And Why It Is Needed?

JSP tags are extended through developing a custom set of tags which is known as as tag library (taglib). The page which makes use of custom tags broadcasts taglib and uniquely names, defines and friends a tag prefix to distinguish using those tags.

Q46. What Is Jsp Technology?

Java Server Page is a trendy Java extension this is defined on pinnacle of the servlet Extensions. The purpose of JSP is the simplified advent and management of dynamic Web pages. JSPs are cozy, platform-independent, and high-quality of all, employ Java as a server-facet scripting language.

Q47. What Is Page Directive?

• A page directive is to tell the JSP engine about the headers or facilities that page ought to get from the environment.

• Typically, the web page directive is located on the top of virtually all of our JSP pages.

• There may be any wide variety of web page directives inside a JSP web page (despite the fact that the attribute – value pair ought to be unique).

• The syntax of the encompass directive is: <%@ page attribute="value">

• Example:<%@ include file="header.Jsp" %>

Q48. How Do I Prevent The Output Of My Jsp Or Servlet Pages From Being Cached By The Browser?

You will need to set the precise HTTP header attributes to save you the dynamic content output through the JSP page from being cached via the browser. Just execute the following scriptlet at the beginning of your JSP pages to prevent them from being cached on the browser. You need both the statements to take care of some of the older browser variations.

Q49. Is Jsp Technology Extensible?

YES. JSP generation is extensible via the improvement of custom movements, or tags, which are encapsulated in tag libraries.

Q50. What Is The Include Directive?

There are thirteen attributes defined for a page directive of which the importantattributes are as follows:

• The encompass directive is used to statically insert the contents of a resource into the modern JSP.

• This permits a person to reuse the code with out duplicating it, and consists of the contents of the desired report on the trlation time.

• The syntax of the include directive is as follows:

<%@ include file = "FileName" %>

• This directive has best one attribute referred to as report that specifies the name of the file to be covered.




CFG