CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies
Servlet Interview Questions & Answers - Learning Mode
COOLINTERVIEW.COM J2EE INTERVIEW QUESTIONS SERVLET INTERVIEW QUESTIONS QUESTIONS & ANSWERS - LEARNING MODE

Servlet Interview Questions & Answers - Learning Mode

A servlet is a Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by web servers. A servlet is a small program that runs on a server. The term was coined in the context of the Java applet, a small program that is sent as a separate file along with a Web (HTML) page. Java servlets are becoming increasingly popular as an alternative to CGI programs. The biggest difference between the two is that a Java applet is persistent.

Try Servlet Interview Questions & Answers - Exam Mode

1 2 3 4 5 6 7 8 9 10 Next

Sort By : Latest First | Oldest First | By Rating

Servlet Interview Questions & Answers - Learning Mode
Try Servlet Interview Questions & Answers - Exam Mode
Question: What are the uses of Servlets?

Answer: A servlet can handle multiple requests concurrently, and can synchronize requests. This allows servlets to support systems such as on-line conferencing. Servlets can forward requests to other servers and servlets. Thus servlets can be used to balance load among several servers that mirror the same content, and to partition a single logical service over several servers, according to task. Source: CoolInterview.com
Question: Difference between single thread and multi thread model serv

Answer: Typically, a servlet class is instantiated the first time it is invoked. The same instance will be used over several client requests, so all members that are declared in that servlet are shared accross clients.

That is what is meant by multi threaded model, multiple clients that access the same instance. There are situations where you want to protect your servlet member variables from being modified by different clients.

In this case, you can have your servlet implement the marke Source: CoolInterview.com
Question: Why init is used and not constructor for servlets initialization?



Answer: The original reason for init() was that ancient versions of Java couldn?t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won?t have access to a ServletConfig or ServletContext. Source: CoolInterview.com
Question: What is the difference between servlets and jsp?

Answer: In servlet,java will be used to generate dynamic HTML pages,but in JSP,java will be reduced and we can use our custom tags to generate HTML pages. Source: CoolInterview.com
Question: What is the diff b/w doGet() and service() method?



Answer: Well the service method tries to determine which of the doXXX method needs to be called.Appropriately either doGet, doPost, doDelete, doPut etc etc are called, Source: CoolInterview.com
Question: Difference between application server and web sever?

Answer: Web server serves pages for viewing the web browser( i.e HTML,JSP,ASP etc.)using http protocol. While application server handles business logic,such as transaction processing,messaging ,resource pooling, security and messaging etc.Both are accessing via the http request, so from the client view point there no much difference. Source: CoolInterview.com
Question: What is the servlet life cycle?

Answer: Each servlet has the same life cycle:
A server loads and initializes the servlet (init())
The servlet handles zero or more client requests (service())
The server removes the servlet (destroy()) (some servers do this step only when they shut down). Source: CoolInterview.com
Question: how do you compile servlet program?

Answer: servlet program is compiled by java compiler Source: CoolInterview.com
Question: Types of Servlets?


Answer: Servlets must implement the interface javax.servlet.Servlet. There are two main types of servlets:

Generic servlets extend javax.servlet.GenericServlet. Generic servlets are protocol independent, meaning that they contain no inherent support for HTTP or any other transport protocol.

HTTP servlets extend javax.servlet.HttpServlet. These servlets have built-in support for the HTTP protocol and are much more useful in an Browser environment
Source: CoolInterview.com
Question: How can a web container know whether cookies are accepted or not accepted by the browser



Answer: The only way to know for sure is to set a cookie on a response, and see if
it comes back on the following request. You have absolutely no clue from
looking just at the current request. Just as an example, I run Netscape
6, configured to warn me every time about accepting a cookie -- so you
can't even look at the User-Agent header and predict whether *I* am going
to accept your cookie or not.

This is exactly what the servlet container does for you for session IDs,
a Source: CoolInterview.com
Question: What is the difference between servlet context and servlet config






Answer: ServletConfig is a servlet configuration object used by a servlet container used to pass information to a servlet during initialization. All of its initialization parameters can ONLY be set in deployment descriptor.

The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized.

You can specify param-value pairs for ServletContext object in <context-param> tags in web.xml file.

The Se Source: CoolInterview.com
Question: What is the difference between the getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface?

Answer: The getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet. If the path begins with a "/" it is interpreted as relative to the current context root.

The getRequestDispatcher(String path) method of javax.servlet.ServletContext interface cannot accepts relative paths. All path must sart with a "/" and are interpreted as relative t Source: CoolInterview.com
Question: What is difference between servlet and ASP?



Answer: Platform and Server IndependenceJSP technology adheres to the Write Once, Run AnywhereTM philosophy of the JavaTM architecture. Instead of being tied to a single platform or vendor, JSP technology can run on any Web server and is supported by a wide variety of tools from multiple vendors.Open Development Process, Open SourceWorking with Sun in the JSP effort are authoring tool vendors (such as Macromedia), container companies (such as Apache and Netscape), end users, consultants, and others.The Source: CoolInterview.com
Question: What is the difference between GenericServlet and HttpServlet?

Answer: GenericServlet is for servlets that might not use HTTP, like for instance FTP service.As of only Http is implemented completely in HttpServlet. The GenericServlet has a service() method that gets called when a client request is made. This means that it gets called by both incoming requests and the HTTP requests are given to the servlet as they are. Source: CoolInterview.com
Question: When a servlet accepts a call from a client, it receives two objects. What are they?

Answer: ServeltRequest: which encapsulates the communication from the client to the server.
ServletResponse: which encapsulates the communication from the servlet back to the client.
ServletRequest and ServletResponse are interfaces defined by the javax.servlet package. Source: CoolInterview.com
Question: What is the difference between servlets and applets?

Answer: Servlets are to servers. Applets are to browsers. Unlike applets, however, servlets have no graphical user interface. Source: CoolInterview.com
Question: How we can check in particular page the session will be alive or not?



Answer: U can use request.getSession(false); method in HttpServletRequest interface.It returns the HttpSession associated with this request or null if the request has no valid session. Source: CoolInterview.com
Question: What is pure servlet?



Answer: Pure servlet means we create any java objets that is implemented from javax.servler.Servlet interface.

Source: CoolInterview.com
Question: Is servlet is used to create a dynamic webpage or Static webpage or both?




Answer: Yes both servlet is used to create a static and dynamic webpage,it also create a static webpage using serverside include it is .shtml extension,and so servlet is flexible character. Source: CoolInterview.com
Question: When we have the servlets/struts what is the perpose of EJB



Answer: EJBs have totally different purpose than Servlets/Struts. EJBs are used for business components which require some basic set of features like transaction/persistance etc. and EJBs are hosted in Application servers.Serlvets are used for handling HTTP requests and generally for generating dynamic content for web page. And struts is a framework for Web application. http://struts.apache.org/ Source: CoolInterview.com

1 2 3 4 5 6 7 8 9 10 Next



India News Network
Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
Cache = 0.03125 Seconds