0% found this document useful (0 votes)
142 views

Adv Java Quiz 2

The document contains 10 multiple choice questions about servlets. The questions cover topics like how to initialize servlets, defining deployment descriptors, chaining servlets, preventing direct access to files, interfaces for request/response, headers, state management in HTTP, and differences between applets and servlets.

Uploaded by

Nikhil Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views

Adv Java Quiz 2

The document contains 10 multiple choice questions about servlets. The questions cover topics like how to initialize servlets, defining deployment descriptors, chaining servlets, preventing direct access to files, interfaces for request/response, headers, state management in HTTP, and differences between applets and servlets.

Uploaded by

Nikhil Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

1) Carefully read the question and answer accordingly.

You being a software developer needs to develop a web application for your
organization. You decided to use servlets to create the web application. While you
are creating the servlet you feel the need to write the code for the initialization
of the servlet. This is needed to initialize the servlet with the required data
after the servlet instance has been created. How will you perform this task?

A. By overriding the service method in the servlet class.


B. By overriding the init method in the servlet class.
C. By overriding the destroy method in the servlet class.
D. By overriding the doGet method in the servlet class.

2) Carefully read the question and answer accordingly.


Manoj has created the Hello servlet that displays Welcome in the browser window.
The code of the servlet is:
package myworld;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class hello extends HttpServlet
{
protected void doGet(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException
{
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>My Servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h>WELCOME</h>");
out.println("</body>");
out.println("</html>");
out.close();
}
}
Which of the following code snippets correctly defines the deployment descriptor
for the preceding servlet?

A. <servlet> <servlet-name>hello</servlet-name> <servlet-


class>hello</servlet-class> </servlet> <servlet-mapping> <servlet-
name>hello</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping>
B. <servlet> <servlet-name>hello</servlet-name> <servlet-
class>myworld.hello</servlet-class> </servlet> <servlet-mapping> <servlet-
name>hello</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping>
C. <servlet> <servlet-name>myworld.hello</servlet-name> <servlet-
class>hello</servlet-class> </servlet> <servlet-mapping> <servlet-
name>hello</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping>
D. <servlet> <servlet-name>hello</servlet-name> <servlet-
class>myworld.hello</servlet-class> </servlet> <servlet-mapping> <servlet-
name>hello</servlet-name> <url-pattern>hello</url-pattern> </servlet-mapping>

3) Carefully read the question and answer accordingly.


Which of the following codes will allow the user to load the servlet using form.
The form should first display submit button and when the user clicks on submit
button it should load the servlet called myservlet?

A. <HTML> <BODY> <FORM ACTION=http://localhost:8080/servlet/myservlet


METHOD=GET> </FORM> </BODY> </HTML>
B. <HTML> <BODY> <FORM ACTION=http://localhost:8080/servlet/myservlet
METHOD=GET> <INPUT TYPE=SUBMIT VALUE=SUBMIT> </FORM> </BODY> </HTML>
C. <HTML> <BODY> <INPUT TYPE=SUBMIT VALUE=SUBMIT> </FORM> </BODY>
</HTML>
D. <HTML> <BODY> <FORM ACTION=http://localhost:8080/servlet METHOD=GET>
<INPUT TYPE=SUBMIT VALUE=SUBMIT> </FORM> </BODY> </HTML>

4) Carefully read the question and answer accordingly.


Select the code to chain a servlet with another servlet

A. RequestDispatcher dispatcher =
request.getRequestDispatcher("Servlet2"); dispatcher.forward(req, resp);
B. RequestDispatcher dispatcher =
request.getRequestDispatcher("Servlet2"); dispatcher.dispatch(req, resp);
C. RequestDispatcher dispatcher =
request.getRequestDispatcher("Servlet2"); dispatcher.chain(req, resp);
D. request.sendRedirect("Servlet2");

5) Carefully read the question and answer accordingly.


Mahesh has observed that some users are able to directly access the content files
stored in the Web application from the Web browser. Which of the following options
should Mahesh use to prevent the users from directly accessing the content files?

A. By storing the content files under the dist directory


B. By storing the content files under the META-INF directory
C. By storing the content files under the WEB-INF directory
D. By storing the content files under the INF directory

6) Carefully read the question and answer accordingly.


Which of the following is an interface that gets data from the client and sends it
to the servlet?

A. ServletRequest
B. ServletResponse
C. PrintStream
D. ServletConfig

7) Carefully read the question and answer accordingly.


Whenever a request goes from the client to the server some additional information
other than the request is also passed to the server. This additional information is
in the form of a ____________.

A. footer
B. header
C. Application ID
D. Session ID

8) Carefully read the question and answer accordingly.


Which of the following is an interface that gets data from the client and sends it
to the servlet?

A. ServletRequest
B. ServletResponse
C. PrintStream
D. ServletConfig

9) Carefully read the question and answer accordingly.


HTTP cannot save state information between one request and other

A. TRUE
B. FALSE

10) Carefully read the question and answer accordingly.


Consider the following statements:
Statement A: Modules of Java code run in a server application is called Applet
Statement B: Modules of Java code run at client side is called Servlet
Which of the following is true about these statements?

A. Statement A is true and statement B is true.


B. Statement A is true and statement B is false.
C. Statement A is false and statement B is true.
D. Statement A is false and statement B is false.

You might also like