Advanced servlets questions

Q.How do you communicate between the servlets.
Ans:
a)servlet chaning
b)Servlet context(RequestDespatcher interface)

Q.Can you send the mail from a servlet ,if yes tell how?
Ans:
Yes.We can do using mail API.

Q.How do you access variables across the sessions.
Ans:
Through ServletContext ,we can access the sessions.

Q.where the session data will store?
ans:
session objects.

Q.What is Servlet Context?
Ans:
This object represents resources shared by a group of servlets like
servlet’s environment,Application attributes shared in the context
level.

Q.How do you trap the debug the errors in servlets.
Ans:
error log file.

Q.How do you debug the Servlet?
Ans:
Through servlet log().

Q.How do u implement threads in servlet?
Ans:
Internally implemented in servlets.

Q.How do you handle DataBase access and in which method of the servlet do you like to create connection.
Ans:
init()

Q.If you want to improve the performance how do you create connections for multiple users?
A.
Connection Pooling.

Q.what is connection pooling?
Ans:
Class which manages no of user requests for connections to improve the
performance.

Q. What are the different servers available for developing and deploying Servlets?
Ans:
a) JRun2.0–Allaire
b) Apache –jserv
c) jwsdk2.0 –sun
d) servletexec
e) Tomcat webserver–tomcat
f) Weblogic AS–BEA Systems
g) NetDynamics5.0–sun
h) Iplanet–sun&netscape
i) Netscape–netscape
g) IBM websphere–IBM
h) oracle–oracle
i) Proton-Pramati technologies

Q. Is it possible to communicate from an applet to servlet and how many ways and how?
Ans:
Yes, there are three ways to communicate from an applet to servlet and
they are:
a) HTTP Communication(Text-based and object-based)
b) Socket Communication
c) RMI Communication

(You can say, by using URL object open the connection to server
and get the InputStream from URLConnection object).
Steps involved for applet-servlet communication:
step: 1 Get the server URL.
URL url = new URL();
step: 2 Connect to the host
URLConnection Con = url.openConnection();
step: 3 Initialize the connection
Con.setUseCatches(false):
Con.setDoOutput(true);
Con.setDoInput(true);
step: 4 Data will be written to a byte array buffer so that we can tell the server the length of the data.
ByteArrayOutputStream byteout = new ByteArrayOutputStream();
step: 5 Create the OutputStream to be used to write the data to the buffer.
DataOutputStream out = new DataOutputStream(byteout);

Q. Why should we go for interservlet communication?
Ans:
Servlets running together in the same server communicate with each
other in several ways.The three major reasons to use interservlet communication are:
a)

    Direct servlet manipulation

- allows to gain access to the other currently loaded servlets and perform certain tasks (through the ServletContext object)
b)

    Servlet reuse

- allows the servlet to reuse the public methods of another servlet.
c)

    Servlet collaboration

- requires to communicate with each other by sharing specific information (through method invocation)

Q.Is it possible to call servlet with parameters in the URL?
Ans:
Yes. You can call a servlet with parameters in the syntax as
(?Param1 = xxx || m2 = yyy).

Q. What is Servlet chaining?
Ans:
Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request.In servlet chaining, one servlet’s output is piped to the next servlet’s input. This process continues until the last servlet is reached. Its output is then sent back to the client.

Q.How do servlets handle multiple simultaneous requests?
Ans:
The server has multiple threads that are available to handle requests. When a request comes in, it is assigned to a thread, which calls a service method (for example: doGet(), doPost( ) and service( ) ) of the servlet. For this reason, a single servlet object can have its service methods called by many threads at once.

Q. How are Servlets and JSP Pages related?
Ans:
JSP pages are focused around HTML (or XML) with Java codes and JSP tags inside them. When a web server that has JSP support is asked for a JSP page, it checks to see if it has already compiled the page into a servlet. Thus, JSP pages become servlets and are transformed into pure Java and then compiled, loaded into the server and executed.Servlets:

Q.How do servlets handle multiple simultaneous requests?
Ans:
Using Threads.

Q.How do I automatically reload servlets?
Ans:
Depends upon the server’s servlet reload properites.

Q.My servlet, which ran correctly under the Servlet 2.0 APIs (Java Web Server 1.1.3) is not running under the Servlet 2.1 APIs (Java Web Server 2.0). What’s wrong?
Ans:
You might have used servlet to servlet communication by usingservletcontext methods like getServlet(),getServlets() which are depricated and returns null from new release that is from servlet2.1 API.

Q.What are the types of ServletEngines?
Ans:

    Standalone ServletEngine

: A standalone engine is a server that includes built-in support for servlets.
Add-on ServletEngine: Its a plug-in to an existing server.It adds servlet support to a server that was not originally designed with servlets in mind.Embedded ServletEngine: it is a lightweight servlet deployment platform that can be embedded in another application.that application become true server.

Leave a Reply

You must be logged in to post a comment.