Question 1. Can We Use The Constructor, Instead Of Init(), To Initialize Servlet?
Yes. But you will now not get the Servlet unique matters from constructor. The unique cause for init() turned into that historic variations of Java couldn’t dynamically invoke constructors with arguments, so there has been no way to present the constructor a ServletConfig. That no longer applies, however servlet containers nonetheless will most effective name your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.
Question 2. What Is Servlet Context?
The Servlet context is an object that includes a records approximately the Web application and box. Using the context, a Servlet can log events, achieve URL references to assets, and set and store attributes that different Servlet within the context can use.
XML Interview Questions
Question 3. What Is A Servlet Filter?
Servlet filters are pluggable Web additives that allow us to put in force pre-processing and publish-processing common sense in our Web applications.
Question four. What Is A War File?
WAR stands for Web Archive. It is a compressed model of your web application. You can use this WAR document to install your net application.
Question five. How Would You Create Deadlock On Your Servlet?
Calling a doPost() approach inner doGet() and doGet()technique inside doPost() wouleate a deadlock for a servlet.
J2EE Interview Questions
Question 6. Why Is Httpservlet Declared Abstract?
1.The default implementations of the main provider techniques can not do some thing and want to be overridden. This calls of the HttpServlet magnificence to be declared as abstract.
2.With its use the developers do no longer need to put into effect all of the carrier techniques.
Question 7. Why Is A Constructor Needed In A Servlet Even If We Use The Init Method?
1.Although the init method of the servlet initializes it, a constructor instantiates it.
2.A developer may by no means explicitly name the servlet's constructor however a box uses it to create an example of the servlet.
J2EE Tutorial JDBC Interview Questions
Question 8. What Is Genericservlet Class?
1.GenericServlet is an abstract elegance which implements the Servlet interface and the ServletConfig interface.
2.Other than the strategies blanketed in above two interfaces, it additionally provides simple variations of the lifecycle techniques init and destroy, and implements the log method declared within the ServletContext interface.
3.Since this magnificence is not unique to any protocol, it is referred to as generic servlet.
Question nine. How Can The Session In Servlet Be Destroyed?
There are ways to ruin a consultation:
1. Programatically : By the usage of consultation.Invalidate() technique. It makes the field abandon the consultation on which the technique is referred to as.
2. When the server shuts down.
JSP Interview Questions
Question 10. What Is Lazy Loading?
The servlets are not initialized via the field from the begin. It occurs while the servlet is asked for the first time. This is referred to as lazy loading.
Question eleven. What Are The Mechanisms Used By A Servlet Container For Maintaining Session Information?
For maintaining session statistics Servlet Container makes use of:
. URL rewriting
. HTTPS protocol information
EJB(Enterprise JavaBeans) Interview Questions
Question 12. What Is The Procedure For Initializing A Servlet?
- To initialize a servlet init() is used.
- init() initializes a java application.
- A constructor also can be used to initialize a servlet.
XML Interview Questions
Question 13. What Is The Web Container?
A Servlet and JSP containers are together called Web containers.
Question 14. What Are The Uses Of Servletrequest?
The ServletRequest gives facts which includes the names of the parameters exceeded by way of the customer, the protocol (scheme) being used by the client, and the names of the far flung host that made the request and the server that received it. The enter flow, ServletInputStream.
Question 15. What Are The Uses Of Servletresponse Interface?
ServletResponse permits the servlet to set the content duration and MIME type of that reaction. It gives an output flow, ServletOutputStream and a Writer via which the servlet can send statistics.
Remote Method Invocation Interview Questions
Question sixteen. How Http Servlet Handles Client Requests?
An HTTP Servlet handles purchaser requests via its carrier approach. The carrier technique helps wellknown HTTP customer requests by dispatching each request to a technique designed to deal with that request.
EJB(Enterprise JavaBeans) Tutorial
Question 17. What Is Pre Initialization Of A Servlet?
A field would not initialize the servlets whilst it starts up. It initializes a servlet whilst it gets a request for that servlet first time. This is referred to as lazy loading. The servlet specification defines the <load-on-startup> detail, which can be detailed inside the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts offevolved up. The technique of loading a servlet earlier than any request is available in is called preloading or pre initializing a servlet.
JNDI (Java Naming and Directory Interface) Interview Questions
Question 18. How Do Servlets Handle Multiple Simultaneous Requests?
When a request comes in, the internet server will start a brand new thread and the request is assigned to a thread, which calls a carrier method of the servlet.
J2EE Interview Questions
Question 19. What Is Servlet Chaining?
Servlet chaining is a way in which or extra servlets can cooperate in servicing a unmarried request. In servlet chaining, one servlet’s output is the enter of subsequent servlet. This procedure continues till the last servlet is reached. Its output is then despatched lower back to the consumer. We are reaching Servlet Chaining with the help of RequestDispatcher.
Java Bean Utils Tutorial
Question 20. How Will You Communicate From An Applet To Servlet?
There are three approaches to talk from an applet to servlet and they are: HTTP Communication (Text-based and item-based) , Socket Communication and RMI Communication.
Java Bean Utils Interview Questions
Question 21. How Do You Communicate Between The Servlets?
We can communicate among servlets by means of using RequestDespatcher interface and servlet chaining.
Question 22. What Is The Difference Between Context Init Parameter And Servlet Init Parameter?
Servlet init parameters are for a unmarried servlet simplest. No body out aspect that servlet can get right of entry to that. It is said in the <servlet> tag inside Deployment Descriptor, where as context init parameter is for the entire web utility. Any servlet or JSP in that internet application can access context init parameter. Context parameters are declared in a tag <context-param> without delay in the <web-app> tag. The strategies for getting access to context init parameter is getServletContext ().GetInitParamter (“name”) in which as method for having access to servlet init parameter is getServletConfig ().GetInitParamter (“call”);
Question 23. What Are The Different Ways For Getting A Servlet Context?
We will get ServletContext with the aid of calling getServletConfig ().GetServletContext (). This is because a ServletConfig always hold a reference to ServletContext. By calling this.GetServletContext () additionally we will get a ServletContext object.
Apache Tomcat Interview Questions
Question 24. What Is Http Tunneling?
HTTP tunneling is used to encapsulate other protocols in the HTTP or HTTPS protocols. Normally the intranet is blocked via a firewall and the network is uncovered to the outer world best thru a particular Web server port, that listens for most effective HTTP requests. To use any other protocol, that with the aid of passes the firewall, the protocol is embedded in HTTP and send as HttpRequest.
JDBC Interview Questions
Question 25. What Are The Differences Between A Session And A Cookie?
Session is saved in server however cookie stored in consumer. Session need to paintings no matter the settings on the consumer browser. There is no restrict on the quantity of statistics that may be saved on session. But it is restricted in cookie. Session can store items and cookies can keep handiest strings. Cookies are quicker than session.
Question 26. Why Should We Go For Inter Servlet Communication?
The 3 essential motives to use inter servlet conversation are:
a) Direct servlet manipulation - allows to gain get right of entry to to the alternative currently loaded servlets and carry out sure tasks (thru the ServletContext object)
b) Servlet reuse - permits the servlet to reuse the general public techniques of another servlet.
C) Servlet collaboration - calls for to speak with every other through sharing precise records (thru approach invocation).
GlassFish Interview Questions
Question 27. What Is Client Side Refresh?
The popular HTTP protocols ways of refreshing the page, which is normally supported through all browsers.
<META HTTP-EQUIV="Refresh" CONTENT="5; URL=/servlet/MyServlet/">
This will refresh the page in the browser routinely and loads the brand new records every 5 seconds.
JSP Interview Questions
Question 28. What Is Server Side Push?
Server Side push is beneficial when information wishes to trade frequently at the customers utility or browser, with out intervention from patron. The mechanism used is, while purchaser first connects to Server, then Server continues the TCP/IP connection open.
Question 29. What's The Servlet Interface?
The significant abstraction inside the Servlet API is the Servlet interface. All servlets enforce this interface, both at once or, extra commonly, by way of extending a class that implements it such as HttpServlet.
Website Builder Interview Questions
Question 30. What Is The Difference Between Servletcontext And Servletconfig?
The ServletConfig offers the facts approximately the servlet initialization parameters. The servlet engine implements the ServletConfig interface so that you can bypass configuration facts to a servlet. The server passes an object that implements the ServletConfig interface to the servlet's init() technique.
The ServletContext gives statistics about the box. The ServletContext interface offers facts to servlets concerning the environment wherein they're strolling. It additionally provides widespread manner for servlets to write occasions to a log file.