YouTube Icon

Interview Questions.

Top 100+ Jsp Interview Questions And Answers - May 31, 2020

fluid

Top 100+ Jsp Interview Questions And Answers

Question 1. What Is A Jsp And What Is It Used For?

Answer :

Java Server Pages (JSP) is a platform independent presentation layer generation that incorporates SUN s J2EE platform. JSPs are ordinary HTML pages with Java code pieces embedded in them. JSP pages are stored to *.Jsp documents. A JSP compiler is used within the background to generate a Servlet from the JSP web page.

Question 2. What Are The Two Kinds Of Comments In Jsp And What's The Difference Between Them ?

Answer :

<%-- JSP Comment --%>
<!-- HTML Comment -->

J2EE Interview Questions
Question three. What Is Jsp Technology?

Answer :

Java Server Page is a standard Java extension this is described on top of the servlet Extensions. The goal of JSP is the simplified advent and control of dynamic Web pages. JSPs are cozy, platform-impartial, and first-rate of all, make use of Java as a server-facet scripting language.

Question four. What Is Jsp Page?

Answer :

A JSP page is a textual content-primarily based document that incorporates two forms of text: static template statistics, which may be expressed in any text-primarily based layout consisting of HTML, SVG, WML, and XML, and JSP factors, which construct dynamic content.

J2EE Tutorial
Question five. What Are The Implicit Objects?

Answer :

Implicit gadgets are items which might be created by using the web box and contain data related to a particular request, web page, or software. They are:
--request
--response
--pageContext
--session
--utility
--out
--config
--page
--exception

Core Java Interview Questions
Question 6. How Many Jsp Scripting Elements And What Are They?

Answer :

There are three scripting language elements:
--declarations
--scriptlets
--expressions

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

Answer :

Because no plug-ins or safety coverage files are wanted on the consumer structures(applet does). Also, JSP pages allow cleanser and extra module utility layout because they provide a way to split programs programming from web web page layout. This manner personnel concerned in web page design do no longer want to recognize Java programming language syntax to do their jobs.

Core Java Tutorial JDBC Interview Questions
Question eight. Is Jsp Technology Extensible?

Answer :

YES. JSP era is extensible through the improvement of custom movements, or tags, that are encapsulated in tag libraries.

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

Answer :

Yes , of path you can use the constructor in place of init(). There’s not anything to prevent you. But you shouldn’t. The authentic purpose for init() become that historic versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to offer the constructur a ServletConfig. That now not applies, however servlet packing containers nevertheless will simplest name your no-arg constructor. So you received’t have get right of entry to to a ServletConfig or Servlet Context.

Java Servlets Interview Questions
Question 10. How Can A Servlet Refresh Automatically If Some New Data Has Entered The Database?

Answer :

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

JDBC Tutorial
Question eleven. The Code In A Finally Clause Will Never Fail To Execute, Right?

Answer :

Using System.Go out(1); in attempt block will not permit in the end code to execute.

Hibernate Interview Questions
Question 12. How Many Messaging Models Do Jms Provide For And What Are They?

Answer :

JMS offer for two messaging fashions, submit-and-subscribe and factor-to-point queuing.

J2EE Interview Questions
Question 13. What Information Is Needed To Create A Tcp Socket?

Answer :

The Local Systems IP Address and Port Number. And the Remote System’s IPAddress and Port Number.

Java Servlets Tutorial
Question 14. What Class.Forname Will Do While Loading Drivers?

Answer :

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

Question 15. How To Retrieve Warnings?

Answer :

SQLWarning objects are a subclass of SQLException that deal with database get admission to warnings. Warnings do not stop the execution of an application, as exceptions do; they absolutely alert the person that some thing did no longer happen as deliberate. A caution can be stated on a Connection item, a Statement item (consisting of PreparedStatement and CallableStatement items), or a ResultSet object. Each of these lessons has a getWarnings approach, which you must invoke that allows you to see the primary caution stated on the calling object .

SQLWarning warning = stmt.GetWarnings();
if (warning != null)

even as (warning != null)

System.Out.Println("Message: " + warning.GetMessage());
System.Out.Println("SQLState: " + caution.GetSQLState());
System.Out.Print("Vendor errors code: ");
System.Out.Println(warning.GetErrorCode());
caution = caution.GetNextWarning();

JavaServer Faces (JSF) Interview Questions
Question sixteen. How Many Jsp Scripting Elements Are There And What Are They?

Answer :

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

Hibernate Tutorial
Question 17. In The Servlet 2.4 Specification Singlethreadmodel Has Been Deprecated, Why?

Answer :

Because it isn't always practical to have such model. Whether you place isThreadSafe to true or false, you have to cope with concurrent consumer requests to the JSP page with the aid of synchronizing get entry to to any shared objects defined at the web page degree.

JSTL(JSP Standard Tag Library) Interview Questions
Question 18. What Are Stored Procedures? How Is It Useful?

Answer :

A stored technique is a fixed of statements/instructions which are living in the database. The saved manner is pre-compiled and saves the database the attempt of parsing and compiling square statements every time a question is run. Each database has its own saved method language, generally a variation of C with a SQL preproceesor. Newer variations of db’s guide writing saved methods in Java and Perl too. Before the arrival of 3-tier/n-tier structure it turned into pretty common for stored procs to put into effect the enterprise good judgment( A lot of structures nevertheless do it). The largest benefit is of path velocity. Also positive sort of statistics manipulations aren't performed in SQL. Stored procs offer a mechanism to do these manipulations. Stored procs also are beneficial when you want to do Batch updates/exports/houseKeeping kind of stuff at the db. The overhead of a JDBC Connection can be sizable in these instances.

Core Java Interview Questions
Question 19. How Do I Include Static Files Within A Jsp Page?

Answer :

Static sources have to constantly be covered the usage of the JSP include directive. This manner, the inclusion is carried out just as soon as for the duration of the translation segment. Do observe that you should always supply a relative URL for the report characteristic. Although you may additionally encompass static sources the usage of the motion, this is not beneficial as the inclusion is then achieved for every and every request.

JavaServer Faces (JSF) Tutorial
Question 20. Why Does Jcomponent Have Add() And Remove() Methods But Component Does Not?

Answer :

Because JComponent is a subclass of Container, and may comprise other components and jcomponents. How can I implement a thread-safe JSP page? - You can make your JSPs thread-secure with the aid of having them put into effect the SingleThreadModel interface. This is finished by way of adding the directive <%@ page isThreadSafe="false" % > within your JSP page.

 

JBOSS Interview Questions
Question 21. How Do I Prevent The Output Of My Jsp Or Servlet Pages From Being Cached By The Browser?

Answer :

You will need to set the right HTTP header attributes to prevent the dynamic content material output with the aid of the JSP web page from being cached by means of the browser. Just execute the following scriptlet at the start of your JSP pages to prevent them from being cached at the browser. You want each the statements to take care of some of the older browser variations.

Question 22. How Do You Restrict Page Errors Display In The Jsp Page?

Answer :

You first set "Errorpage" characteristic of PAGE listing to the call of the error page (ie Errorpage= "mistakes.Jsp")for your jsp page .Then in the errors jsp page set "isErrorpage=TRUE". When an error occur on your jsp web page it will routinely call the error page.

JBOSS Tutorial
Question 23. What Jsp Lifecycle Methods Can I Override?

Answer :

You can not override the _jspService() technique within a JSP page. You can however, override the jspInit() and jspDestroy() techniques inside a JSP web page. JspInit() may be useful for allocating sources like database connections, community connections, and so on for the JSP page. It is good programming practice to free any allotted assets within jspDestroy().

The jspInit() and jspDestroy() methods are each done just once at some stage in the lifecycle of a JSP web page and are commonly declared as JSP declarations:

Log4j Interview Questions
Question 24. How Do I Perform Browser Redirection From A Jsp Page?

Answer :

You can use the response implicit object to redirect the browser to a distinctive aid, as: reaction. Ship Redirect ; You can also physically regulate the Location HTTP header attribute, as shown below: You also can use the:

Also note that you could handiest use this earlier than any output has been despatched to the client. I beleve this is the case with the response.SendRedirect() technique as properly. If you need to pass any paramateres then you can pass the usage of.

JDBC Interview Questions
Question 25. How Does Jsp Handle Run-time Exceptions?

Answer :

You can use the errorPage characteristic of the web page directive to have uncaught runtime exceptions mechanically forwarded to an errors processing web page.
For example: redirects the browser to the JSP web page blunders.Jsp if an uncaught exception is encountered during request processing. Within error.Jsp, if you suggest that it's far an blunders-processing page, thru the directive: the Throwable item describing the exception can be accessed within the mistakes web page through the exception implicit item.

Log4j Tutorial
Question 26. How Do I Use Comments Within A Jsp Page?

Answer :

You can use "JSP-style" remarks to selectively block out code at the same time as debugging or truly to comment your scriptlets. JSP comments are not visible on the purchaser.
For instance:
--%>
You can also use HTML-fashion comments everywhere inside your JSP page. These feedback are visible at the client. For instance: Of direction, you can also use remarks supported by means of your JSP scripting language within your scriptlets.

NHibernate Interview Questions
Question 27. Is It Possible To Share An Httpsession Between A Jsp And Ejb? What Happens When I Change A Value In The Httpsession From Inside An Ejb?

Answer :

You can bypass the HttpSession as parameter to an EJB method, only if all objects in consultation are serializable. This has to be take into account as "surpassed-through-cost", which means that it is study-handiest in the EJB.

If some thing is altered from in the EJB, it won't be meditated returned to the HttpSession of the Servlet Container. The "skip-byreference" may be used between EJBs Remote Interfaces, as they're remote references.

While it IS possible to pass an HttpSession as a parameter to an EJB item, it is considered to be "horrific practice" in terms of object orientated design. This is due to the fact you're growing an needless coupling between back-cease gadgets (ejbs) and the front-stop objects (HttpSession). Create a higher-degree of abstraction on your ejb's api. Rather than passing the whole, fats, HttpSession (which carries with it a gaggle of http semantics), create a category that acts as a fee object (or structure) that holds all of the facts you need to skip to and fro between front-end/again-end.

Consider the case in which your ejb wishes to guide a non-http-based totally purchaser. This higher degree of abstraction will be flexible enough to assist it.

Java Servlets Interview Questions
Question 28. How Can I Implement A Thread-secure Jsp Page?

Answer :

You can make your JSPs thread-secure by having them enforce the SingleThreadModel interface. This is performed by including the directive <%@ page isThreadSafe="false" % > within your JSP page.

NHibernate Tutorial
Question 29. How Can I Declare Methods Within My Jsp Page?

Answer :

You can declare strategies for use inside your JSP page as declarations. The strategies can then be invoked within some other techniques you declare, or within JSP scriptlets and expressions.

Do notice that you do not have direct get right of entry to to any of the JSP implicit gadgets like request, response, session and so on from within JSP methods. However, you ought to be able to pass any of the implicit JSP variables as parameters to the strategies you declare.

For instance:
Another Example:
file1.Jsp:
file2.Jsp
<%test(out);% >

Apache Struts 2 Interview Questions
Question 30. Can I Stop Jsp Execution While In The Midst Of Processing A Request?

Answer :

Yes. Preemptive termination of request processing on an errors condition is a good manner to maximize the throughput of a high-extent JSP engine. The trick (assuming Java is your scripting language) is to use the return announcement whilst you want to terminate further processing.

Question 31. Can A Jsp Page Process Html Form Data?

Answer :

Yes. However, in contrast to Servlet, you are not required to put in force HTTP-protocol specific techniques like doGet() or doPost() inside your JSP web page. You can acquire the records for the FORM enter factors via the request implicit item inside a scriptlet or expression as.

Apache Struts 2 Tutorial
Question 32. Is There A Way To Reference The "this" Variable Within A Jsp Page?

Answer :

Yes, there's. Under JSP 1.0, the page implicit item is equivalent to "this", and returns a connection with the Servlet generated by means of the JSP web page.

Question 33. Is There A Way I Can Set The Inactivity Lease Period On A Per-consultation Basis?

Answer :

Typically, a default inaction lease length for all sessions is set inside your JSPengine admin screen or associated residences record. However, if your JSP engine helps the Servlet 2.1 API, you may control the inactiveness lease period on a in line with-session basis. This is executed by way of invoking the HttpSession.SetMaxInactiveInterval() method, right after the session has been created.

Hibernate Interview Questions
Question 34. How Does A Servlet Communicate With A Jsp Page?

Answer :

The following code snippet suggests how a servlet instantiates a bean and initializes it with FORM records published via a browser. The bean is then positioned into the request, and the decision is then forwarded to the JSP web page, Bean1.Jsp, through a request dispatcher for downstream processing.

Public void doPost (HttpServletRequest request, HttpServletResponse response)

strive 
govi.FormBean f = new govi.FormBean();
String identity = request.GetParameter("id");
f.SetName(request.GetParameter("call"));
f.SetAddr(request.GetParameter("addr"));
f.SetAge(request.GetParameter("age"));
//use the identity to compute
//additional bean properties like info
//perhaps carry out a db query, etc.
// . . .
F.SetPersonalizationInfo(info);
request.SetAttribute("fBean",f);
getServletConfig().GetServletContext().GetRequestDispatcher
("/jsp/Bean1.Jsp").Forward(request, reaction);
 catch (Exception ex) 
. . .

The JSP web page Bean1.Jsp can then method fBean, a fter first extracting it from the default request scope via the useBean movement.

Jsp:useBean identity="fBean" elegance="govi.FormBean" scope="request"/ jsp:getProperty call="fBean"
assets="call" / jsp:getProperty name="fBean"
assets="addr" / jsp:getProperty name="fBean" belongings="age" / jsp:getProperty name="fBean"
assets="personalizationInfo" /

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

Answer :

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

A JSPWriter may be regarded as a buffered version of the circulation item lower back via response.GetWriter(), although from an implementational perspective, it is not.

Question 36. Can A Jsp Page Instantiate A Serialized Bean?

Answer :

No problem! The use Bean movement specifies the beanName characteristic, which can be used for indicating a serialized bean.

For example:

A couple of essential factors to note. Although you'll have to call your serialized document "filename.Ser", you best suggest "filename" as the price for the beanName attribute. Also, you'll ought to region your serialized document inside the WEB-INFjspbeans directory for it to be placed via the JSP engine.

JavaServer Faces (JSF) Interview Questions
Question 37. What Is Jsp?

Answer :

Let's do not forget the solution to that from  unique perspectives: that of an HTML designer and that of a Java programmer.

If you are an HTML fashion designer, you may examine JSP generation as extending HTML to provide you with the capacity to seamlessly embed snippets of Java code inside your HTML pages. These bits of Java code generate dynamic content, that is embedded within the other HTML/XML content you author. Even higher, JSP technology provides the way via which programmers can create new HTML/XML tags and JavaBeans components, which offer new features for HTML designers without those designers desiring to learn how to software.

Note: A commonplace false impression is that Java code embedded in a JSP page is transmitted with the HTML and carried out by means of the person agent (inclusive of a browser). This is not the case. A JSP page is translated right into a Java servlet and performed at the server. JSP statements embedded inside the JSP page end up part of the servlet generated from the JSP page. The ensuing servlet is accomplished on the server. It is in no way visible to the consumer agent. If you're a Java programmer, you may take a look at JSP generation as a brand new, higher-degree means to writing servlets. Instead of directly writing servlet classes after which emitting HTML from your servlets, you write HTML pages with Java code embedded in them. The JSP surroundings takes your web page and dynamically compiles it. Whenever a user agent requests that web page from the Web server, the servlet that become generated from your JSP code is achieved, and the effects are again to the user.

Question 38. How Do I Mix Jsp And Ssi #consist of? What Is The Difference Between Include Directive & Jsp:consist of Action?

Answer :

If you are just which include raw HTML, use the #include directive as standard inside your .Jsp file.

<!--#include file="data.Inc"-->
But it's a touch trickier if you want the server to evaluate any JSP code that is within the blanketed file. If your information.Inc file incorporates jsp code you'll ought to use <%@ vinclude="data.Inc" %>

The is used for which include non-JSP documents.

Include directive - <%@ include file="fileName" %> - as is the case with all other directives in a JSP page, this encompass directive is also processed on the time when the JSP page is translated into its equal servlet. This directive virtually reasons the contents of the required document to be pasted into the JSP page on the location where the page consists of this directive. Irrespective of whether the protected resource is a static useful resource or a JSP page - most effective the contents of the document are pasted (and not the processed effects). This directive is usually used for inclusive of static sources most effective - like, banner, header, footer, and so forth. For the obvious cause.

Include motion -<jsp:include page="relativeURL"></jsp:include> this encompass movement is carried out at run time and the desired 'page' is first performed and then the result of that 'web page' is appended to the reaction object of the calling JSP at the point where the tag happens. Obviously if the required web page is a static resource then the contents of it are covered as there may not be an completed bring about that case. This movement allows extra parameters to be surpassed through child detail of this consist of action detail.

Question 39. How Do You Prevent The Creation Of A Session In A Jsp Page And Why? What Is The Difference Between Include Directive & Jsp:include Action?

Answer :

By default, a JSP web page will automatically create a session for the request if one does now not exist.
However, classes eat assets and if it isn't always essential to keep a session, one must now not be created. For instance, a advertising marketing campaign may advise the reader visit a web web page for extra facts. If it's miles anticipated that a whole lot of visitors will hit that web page, you could need to optimize the burden on the system through no longer developing useless periods.

Question 40. How Can I Set A Cookie And Delete A Cookie From Within A Jsp Page?

Answer :

A cookie, mycookie, can be deleted the usage of the following scriptlet:

<%//creating a cookieCookie mycookie = new Cookie("aName","aValue");
response.AddCookie(mycookie);
//delete a cookieCookie killMyCookie = new Cookie("mycookie", null);
killMyCookie.SetMaxAge(0);killMyCookie.SetPath("/");
response.AddCookie(killMyCookie);%>
JSTL(JSP Standard Tag Library) Interview Questions
Question forty one. How Do You Connect To The Database From Jsp?

Answer :

A Connection to a database may be hooked up from a jsp web page by way of writing the code to establish a connection using a jsp scriptlets.

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

Question 42. What Is The Page Directive Is Used To Prevent A Jsp Page From Automatically Creating A Session?

Answer :

<%@ page session="false">

JBOSS Interview Questions
Question 43. How Do You Delete A Cookie Within A Jsp?

Answer :

Cookie mycook = new Cookie("name","cost");
response.AddCookie(mycook);
Cookie killmycook = new Cookie("mycook","fee");
killmycook.SetMaxAge(0);
killmycook.SetPath("/");
killmycook.AddCookie(killmycook);

Question forty four. Can We Implement An Interface In A Jsp?

Answer :

No

Question forty five. What Is The Difference Between Servletcontext And Pagecontext?

Answer :

ServletContext: Gives the facts about the field
PageContext: Gives the facts about the Request.

Question 46. What Is The Difference In Using Request.Getrequestdispatcher() And Context.Getrequestdispatcher()?

Answer :

request.GetRequestDispatcher(course): In order to create it we need to give the relative route of the aid context.GetRequestDispatcher(path): In order to create it we need to provide the absolute path of the resource.

Question 47. How To Pass Information From Jsp To Included Jsp?

Answer :

Using <%jsp:param> tag.

Question 48. How Is Jsp Include Directive Different From Jsp Include Action. ?

Answer :

When a JSP consist of directive is used, the covered file's code is added into the brought JSP web page at page translation time, this takes place earlier than the JSP web page is translated into a servlet. While if any page is included using action tag, the page's output is back lower back to the added page. This happens at runtime.

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

Answer :

We can override jspinit() and jspDestroy() methods however now not _jspService().

Question 50. Why Is _jspservice() Method Starting With An '_' While Other Life Cycle Methods Do Not?

Answer :

_jspService() technique may be written by using the container consequently any methods which aren't to be overridden by way of the quit person are typically written starting with an '_'. This is the motive why we don't override _jspService() method in any JSP web page.

Question 51. What Happens When A Page Is Statically Included In Another Jsp Page?

Answer :

An include directive tells the JSP engine to include the contents of any other record (HTML, JSP, and many others.) within the modern-day web page. This procedure of together with a record is also called as static encompass.

Question 52. A Jsp Page, Include.Jsp, Has A Instance Variable "int A", Now This Page Is Statically Included In Another Jsp Page, Index.Jsp, Which Has A Instance Variable "int A" Declared. What Happens When The Index.Jsp Page Is Requested By The Client?

Answer :

Compilation error, as  variables with identical call can't be declared. This happens due to the fact, whilst a web page is covered statically, entire code of included page will become a part of the new page. Presently there are  declarations of variable 'a'. Hence compilation mistakes.

Question fifty three. Can You Override Jspinit() Method? If Yes, In Which Cases?

Answer :

yes, we can. We do it generally whilst we want to initialize any participants which can be to be available for a servlet/ JSP in the course of its lifetime.

Question 54. What Is The Difference Between Directive Include And Jsp Include?

Answer :

include directive :

The file gets blanketed on the assemble time.
It's miles static in nature.Output comes with jsp page but entire document carries is included in jsp then compilation is done.
Movement tag :

The document gets included on the run time. This is faster.
It's far dynamic in nature.Output of yhe record willbe protected within the jsp record.
Question fifty five. What Is The Difference Between Requestdispatcher And Sendredirect?

Answer :

RequestDispatcher: server-aspect redirect with request and reaction objects.

SendRedirect : Client-aspect redirect with new request and response gadgets.

Question 56. How Does Jsp Handle Runtime Exceptions?

Answer :

Using errorPage characteristic of web page directive and additionally we want to specify isErrorPage=actual if the modern-day web page is supposed to URL redirecting of a JSP.

Question fifty seven. How Can My Application Get To Know When A Httpsession Is Removed?

Answer :

Define a Class HttpSessionNotifier which implements HttpSessionBindingListener and put into effect the functionality what you need in valueUnbound() technique.
Create an instance of that class and placed that example in HttpSession.

Question fifty eight. What Is A Output Comment?

Answer :

A comment that is sent to the patron inside the viewable page source.The JSP engine handles an output remark as uninterpreted HTML text, returning the remark in the HTML output despatched to the client. You can see the remark through viewing the page source from your Web browser.
JSP Syntax
<!-- comment [ <%= expression %> ] -->
Example 1
<!-- This is a commnet despatched to patron on
<%= (new java.Util.Date()).ToLocaleString()%>
-->
Displays in the page source:
<!-- This is a commnet sent to client on January 24, 2004 -->

Question fifty nine. What Is A Hidden Comment?

Answer :

A remarks that documents the JSP page however isn't despatched to the purchaser. The JSP engine ignores a hidden remark, and does not process any code inside hidden comment tags. A hidden remark is not sent to the customer, either in the displayed JSP page or the HTML page supply. The hidden remark is useful whilst you need to hide or "comment out" a part of your JSP page.

You can use any characters in the frame of the comment besides the final --%> mixture. If you need to apply --%> for your comment, you may get away it by typing --%>. 

JSP Syntax
<%-- comment --%>

Examples
<%@ page language="java" %>
<html>
<head><title>A Hidden Comment </title></head>
<body>
<%-- This comment will not be visible to the colent in the page source --%>
</body>
</html>

Question 60. What Is A Expression?

Answer :

An expression tag incorporates a scripting language expression this is evaluated, converted to a String, and inserted wherein the expression appears in the JSP report. Because the fee of an expression is transformed to a String, you could use an expression inside textual content in a JSP document. Like
<%= someexpression %> 
<%= (new java.Util.Date()).ToLocaleString() %>
You cannot use a semicolon to cease an expression.

Question 61. What Is A Declaration?

Answer :

A announcement declares one or greater variables or methods for use later in the JSP supply record.

A announcement must incorporate as a minimum one complete declarative statement. You can declare any quantity of variables or techniques within one announcement tag, as long as they may be separated through semicolons. The statement should be legitimate in the scripting language used in the JSP document. 
<%! Somedeclarations %>
<%! Int i = 0; %>
<%! Int a, b, c; %>

Question sixty two. What Is A Scriptlet?

Answer :

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

1.Declare variables or strategies to apply later inside the record (see additionally Declaration).
2.Write expressions legitimate within the web page scripting language (see also Expression).
Three.Use any of the JSP implicit items or any item declared with a <jsp:useBean> tag. You must write plain textual content, HTML-encoded text, or other JSP tags out of doors the scriptlet.

Scriptlets are finished at request time, while the JSP engine approaches the purchaser request. If the scriptlet produces output, the output is saved within the out object, from which you could show it.

Question sixty three. What Are Implicit Objects? List Them?

Answer :

Certain gadgets which might be available for the use in JSP files with out being declared first. These gadgets are parsed with the aid of the JSP engine and inserted into the generated servlet. The implicit objects re listed under
• request
• reaction
• pageContext
• session
• software
• out
• config
• web page
• exception.

Question sixty four. Difference Between Forward And Sendredirect?

Answer :

When you invoke a forward request, the request is despatched to another aid ohe server, without the consumer being knowledgeable that a one of a kind aid is going to method the request. This manner occurs completly with within the web container. When a sendRedirtect method is invoked, it reasons the internet field to return to the browser indicating that a new URL have to be asked. Because the browser troubles a completly new request any item that are saved as request attributes before the redirect happens will be lost. This extra spherical experience a redirect is slower than forward.

Question 65. What Are The Different Scope Valiues For The ?

Answer :

The one of a kind scope values for <jsp:useBean> are
1. Page
2. Request
three.Session
four.Application.

Question sixty six. Explain The Life-cycle Mehtods In Jsp?

Answer :

The generated servlet class for a JSP web page implements the HttpJspPage interface of the javax.Servlet.Jsp package. Hte HttpJspPage interface extends the JspPage interface which inturn extends the Servlet interface of the javax.Servlet package deal. The generated servlet elegance accordingly implements all of the strategies of the those 3 interfaces. The JspPage interface proclaims best  mehtods - jspInit() and jspDestroy() that need to be implemented by all JSP page regardless of the purchaser-server protocol. However the JSP specification has furnished the HttpJspPage interfaec particularly for the JSp pages serving HTTP requests.

This interface broadcasts one method_jspService(). 

The jspInit()- The container calls the jspInit() to initialize te servlet example.It is called before another technique, and is referred to as simplest once for a servlet example.

The _jspservice()- The box calls the _jspservice() for each request, passing it the request and the response objects.

The jspDestroy()- The container calls this while it makes a decision take the instance out of service. It is the ultimate technique referred to as n the servlet example.

Question sixty seven. What's A Better Approach For Enabling Thread-safe Servlets And Jsps? Singlethreadmodel Interface Or Synchronization?

Answer :

Although the SingleThreadModel technique is easy to apply, and works well for low quantity sites, it does now not scale properly. If you count on your customers to increase inside the future, you may be higher off enforcing specific synchronization in your shared facts. The key but, is to correctly reduce the quantity of code this is synchronzied so that you take most advantage of multithreading.

Also, be aware that SingleThreadModel is quite aid intensive from the server's angle. The maximum critical problem however is when the range of concurrent requests exhaust the servlet instance pool. In that case, all the unserviced requests are queued till something turns into unfastened - which results in bad performance. Since the utilization is non-deterministic, it may no longer help a whole lot even in case you did upload greater reminiscence and extended the dimensions of the instance pool.

Question 68. What Is The Difference Between Jsp And Servlets ?

Answer :

JSP is used in particular for presentation best. A JSP can handiest be HttpServlet meaning the handiest supported protocol in JSP is HTTP. But a servlet can assist any protocol like HTTP, FTP, SMTP etc.

Question sixty nine. What Is Difference Between Custom Jsp Tags And Beans?

Answer :

Custom JSP tag is a tag you described. You outline how a tag, its attributes and its frame are interpreted, and then institution your tags into collections known as tag libraries that can be utilized in any wide variety of JSP documents. To use custom JSP tags, you need to outline 3 separate additives: the tag handler class that defines the tag's conduct ,the tag library descriptor file that maps the XML detail names to the tag implementations and the JSP document that makes use of the tag library.

JavaBeans are Java software instructions you described. Beans have a trendy format for Java instructions. You use tags .

Custom tags and beans accomplish the equal dreams -- encapsulating complex conduct into easy and handy forms. There are several variations.

Custom tags can manage JSP content; beans can't. Complex operations may be reduced to a significantly less difficult form with custom tags than with beans. Custom tags require pretty a chunk greater work to set up than do beans. Custom tags normally define pretty self-contained conduct, whereas beans are often described in one servlet and used in a specific servlet or JSP web page. Custom tags are available best in JSP 1.1 and later, however beans may be utilized in all JSP 1.X versions.

Question 70. What Are The Different Ways For Session Tracking?

Answer :

Cookies, URL rewriting, HttpSession, Hidden shape fields.

Question 71. What Mechanisms Are Used By A Servlet Container To Maintain Session Information?

Answer :

Cookies, URL rewriting, and HTTPS protocol records are used to maintain session facts.

Question seventy two. Difference Between Get And Post?

Answer :

In GET your whole shape submission may be encapsulated in one URL, like a hyperlink. Query length is confined to 255 characters, not comfy, quicker, short and easy. The records is submitted as a part of URL.

In POST data is submitted internal body of the HTTP request. The facts is not seen at the URL and it's miles more secure.

Question seventy three. What Is Session?

Answer :

The session is an object utilized by a servlet to track a person's interaction with a Web software throughout multiple HTTP requests. The session is saved at the server.

Question seventy four. What Is Servlet Mapping?

Answer :

The servlet mapping defines an association among a URL sample and a servlet. The mapping is used to map requests to Servlets.

Question 75. What Is Servlet Context ?

Answer :

The servlet context is an item that incorporates a records approximately the Web software and container. Using the context, a servlet can log occasions, reap URL references to assets, and set and keep attributes that other servlets within the context can use.

Question seventy six. What Is A Servlet ?

Answer :

servlet is a java application that runs inside a web box.

Question 77. How Is Scripting Disabled?

Answer :

Scripting is disabled by using putting the scripting-invalid element of the deployment descriptor to real. It is a sub detail of jsp-assets-group. Its legitimate values are proper and false. The syntax for disabling scripting is as follows:
<jsp-property-group>
<url-pattern>*.Jsp</url-pattern>
<scripting-invalid>real</scripting-invalid>
</jsp-property-group>

Question seventy eight. What Is A Jsp Expression?

Answer :

A JSP expression is used to write down an output with out the usage of the out.Print assertion. It can be said as a shorthand representation for scriptlets. An expression is written between the <%= and %> tags. It isn't always required to quit the expression with a semicolon, because it implicitly adds a semicolon to all the expressions within the expression tags.

Question seventy nine. What Are Jsp Declarations?

Answer :

As the call implies, JSP declarations are used to declare magnificence variables and methods in a JSP web page. They are initialized while the elegance is initialized. Anything defined in a declaration is to be had for the whole JSP page. A declaration block is enclosed among the <%! And %> tags. A statement isn't always included in theservice() technique whilst a JSP is translated to a servlet.

Question eighty. What Is The Jsp:plugin Action ?

Answer :

This action lets you insert the browser-particular OBJECT or EMBED element needed to specify that the browser run an applet the use of the Java plugin.

Question eighty one. What Are Scripting Elements?

Answer :

JSP scripting elements can help you insert Java code into the servlet in order to be generated from the modern-day JSP page. There are 3 paperwork:

Expressionsof the form <%= expression %> which are evaluated and inserted into the output,
Scriptletsof the shape <% code %> which can be inserted into the servlet's service method,
Declarationsof the shape <%! Code %> which might be inserted into the frame of the servlet elegance, outdoor of any current methods.
Question eighty two. What Is The Standard Action?

Answer :

The <jsp:param> widespread motion is used with <jsp:include> or <jsp:forward> to pass parameter names and values to the goal resource. The syntax of the <jsp:param> fashionable action is as follows: 
<jsp:param name="paramName" value="paramValue"/>

Question eighty three. What Is The Jsp:getproperty Action?

Answer :

The <jsp:getProperty> action is used to access the homes of a bean that turned into set using the <jsp:getProperty> motion. The box converts the belongings to a String as follows:

If it is an object, it makes use of the toString() technique to convert it to a String.
If it is a primitive, it converts it without delay to a String the use of the valueOf() method of the corresponding Wrapper class.
The syntax of the <jsp:getProperty> technique is: <jsp:getProperty name="Name" property="Property" />
Here, name is the identification of the bean from which the belongings became set. The belongings characteristic is the property to get. A user should create or find a bean the use of the <jsp:useBean> movement earlier than the use of the <jsp:getProperty> motion.

Question eighty four. Differentiate Between Pagecontext.Encompass And Jsp:encompass?

Answer :

The <jsp:include> general action and thepageContext.Encompass() method are both used to consist of sources at runtime. However, thepageContext.Consist of() technique continually flushes the output of the cutting-edge page before together with the other components, while<jsp:include> flushes the output of the present day page most effective if the price = of flush is explicitly set to real as follows:
<jsp:include page="/index.Jsp" flush="true"/>

Question 85. What Is The Standard Action?

Answer :

The <jsp:include> standard motion allows the modern JSP web page to include a static or a dynamic resource at runtime. In assessment to the include directive, the encompass motion is used for resources that trade frequently. The resource to be covered ought to be inside the equal context.The syntax of the <jsp:include> trendy motion is as follows:
<jsp:include page="targetPage" flush="true"/> 
Here, targetPage is the web page to be included within the present day JSP.

Question 86. What Is The Standard Action?

Answer :

The <jsp:useBean> general motion is used to locate an present JavaBean or to create a JavaBean if it does not exist. It has attributes to identify the item instance, to specify the life of the bean, and to specify the fully qualified classpath and sort.

Question 87. What Are The Standard Actions Available In Jsp?

Answer :

The widespread actions available in JSP are as follows:

<jsp:include>:It includes a reaction from a servlet or a JSP web page into the contemporary page.It differs from an include directive in that it consists of a resource at request processing time, while the consist of directive includes a aid at translation time.
<jsp:forward>:It forwards a response from a servlet or a JSP 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 sets the residences for a JavaBean.
<jsp:getProperty>:It gets the price of a assets from a JavaBean aspect and adds it to the reaction.
<jsp:param>:It is used in conjunction with <jsp:forward>;, <jsp:, or plugin>; to add a parameter to a request. These parameters are furnished the use of the call-value pairs.
<jsp:plugin>:It is used to consist of a Java applet or a JavaBean inside the modern JSP web page.
 

Question 88. What Are The Jsp Standard Actions?

Answer :

• The JSP preferred actions have an effect on the overall runtime conduct of a JSP page and additionally the reaction sent again to the purchaser.
• They may be used to consist of a file on the request time, to discover or instantiate a JavaBean, to ahead a request to a new web page, to generate a browser-unique code, and so on.
• Ex: include, ahead, useBean,and so forth.

Question 89. What Is The Include Directive?

Answer :

There are thirteen attributes described for a page directive of which the importantattributes are as follows:
• The encompass directive is used to statically insert the contents of a useful resource into the modern-day JSP.
• This permits a person to reuse the code with out duplicating it, and includes the contents of the required document at the interpretation time.
• The syntax of the consist of directive is as follows:
<%@ include file = "FileName" %>
• This directive has most effective one attribute called record that specifies the call of the report to be protected.

Question 90. What Are The Attributes Of Page Directive?

Answer :

There are 13 attributes described for a web page directive of which the vital attributes are as follows:
• import: It specifies the applications which are to be imported.
• session: It specifies whether a session records is to be had to the JSP web page.
• contentType: It lets in a consumer to set the content material-kind for a page.
• isELIgnored: It specifies whether or not the EL expressions are left out whilst a JSP is translated to a servlet.

Question ninety one. What Is Page Directive?

Answer :

• A page directive is to tell the JSP engine approximately the headers or centers that page need to get from the environment.
• Typically, the web page directive is discovered on the top of almost all of our JSP pages.
• There may be any wide variety of page directives within a JSP web page (despite the fact that the characteristic – cost pair have to be particular).
• The syntax of the include directive is: <%@ page attribute="value">
• Example:<%@ include file="header.Jsp" %>

Question ninety two. What Are Jsp Directives?

Answer :

• JSP directives are messages for the JSP engine. I.E., JSP directives function a message from a JSP web page to the JSP field and manipulate the processing of the whole web page.
• They are used to set global values consisting of a class declaration, method implementation, output content material type, etc.
• They do no longer produce any output to the purchaser.
• Directives are usually enclosed within <%@ ….. %> tag.
• Ex: page directive, encompass directive, and so forth.

Question 93. What Are Advantages Of Jsp

Answer :

on every occasion there may be a exchange in the code, we dont should recompile the jsp. It mechanically does the compilation. By using custom tags and tag libraries the period of the java code is decreased.

Question ninety four. How Do I Use A Scriptlet To Initialize A Newly Instantiated Bean?

Answer :

A jsp:useBean motion may optionally have a body. If the frame is precise, its contents could be mechanically invoked whilst the desired bean is instantiated. Typically, the body will comprise scriptlets or jsp:setProperty tags to initialize the newly instantiated bean, although you are not constrained to the usage of those on my own. The following instance indicates the "these days" belongings of the Foo bean initialized to the present day date while it's far instantiated. Note that right here, we make use of a JSP expression in the jsp:setProperty action.
<jsp:useBean id="foo" >
<jsp:setProperty call="foo" assets="nowadays"
price="<%=java.Text.DateFormat.GetDateInstance().Format(new java.Util.Date())
%>"/ >
<%-- scriptlets calling bean setter methods go here --%>
</jsp:useBean >

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

Answer :

<%@ page session="false">

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

Answer :

Create a TLD document and configure the specified class Information.
Create the Java Implementation Source extending the JSP Tag Lib Class (TagSupport).
Compile and bundle it as loosed class document or as a jar below lib folder in Web Archive File for Class loading.
Place the TLD file under the WEB-INF folder.
Add reference to the tag library within the web.Xml document.

Question 97. Outline The Major Difference Between The Session And Cookie?

Answer :

Sessions are constantly stored inside the server facet while cookies are constantly stored within the consumer side.

Question 98. How Method Is Declared Within Jsp Page?

Answer :

Methods can be declared to be used inside JSP page as declaration and this approach can be invoked within any other technique which is asserted or inside JSP scriptlets or expressions. Direct get entry to to the JSP implicit items like request, response, consultation and so on is forbidden inside JSP methods but implicit Java server page variable is allowed to bypass as parameters to the method which is said.

Question 99. Is It Possible By A Jsp Page To Process Html Form Data?

Answer :

Yes it's far possible by way of really acquiring the information from the FORM input through the request implicit object which lies with a scriptlet or expression but it would not require to put in force any HTTP – Protocol strategies like goGet() or doPost() in the JSP web page.

Question one hundred. How Cookies Is Deleted In Jsp?

Answer :

There are two approaches by way of which the cookies can be deleted in JSP. Firstly, through setting the setMaxAge() of the cookie class to zero. And secondly with the aid of placing a timer inside the header document this is reaction. SetHeader(expires Mention the time attribute), to be able to delete the cookies after that prescribed time.

Question one zero one. What Are Custom Tags And Why It Is Needed?

Answer :

JSP tags are prolonged by developing a custom set of tags that is called as tag library (taglib). The web page which makes use of custom tags announces taglib and uniquely names, defines and pals a tag prefix to differentiate using the ones tags.

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

Answer :

The only minor distinction among both the techniques is that Java Server web page ahead technique can’t forward to some other JSP page in every other internet utility or container whereas servlet forward approach can accomplish that.

Question 103. State The Difference Between The Expression And Scriptlet?

Answer :

JSP, Expressions is used to show the values of variable or to go back the values by means of invoking the getter methods. However, JSP expressions begins with <> and does now not have semicolon at the give up of the expression. Scriptlet can incorporate variable, technique or expressions which can be valid inside the page scripting language. Within the scripting tags and page scripting language any legitimate operations can be carried out.

Question 104. How A Run - Time Application Is Handled In Jsp?

Answer :

In JSP the errorpage attribute of the page is used as a directive to have uncaught run – time exceptions and that is routinely forwarded to an web page which tactics the error. If an uncaught exception is encountered while processing the request, then the browser redirects to the JSP mistakes page.

Question 105. What Is Declaration In Jsp?

Answer :

In Java Server pages Declaration is used to claim and define variables and strategies that may be used in the Java Server Pages. The variable which is asserted is initialized once and it maintain its




CFG