OCEJWCD 6 Mock Exam – 1


1 . A web.xml for a web application contains the following:









What should formlogin.html contain?

Choose the one below:

  1. A base 64 encoded username and password
  2. A header that prompts the browser to pop up the username/password dialog
  3. A form that POSTs to j_security_check url
  4. Any html page that does not require the user to login
  5. Code to redirect the user to the login page

2 . Which of the following are valid values for the element of the deployment descriptor?

  4. NONE

3 . You want to add third party classes bundled as a JAR file and a couple of your own classes to a web application. Which directories would you place them in?

  1. JAR file in WEB-INF/lib and class files in WEB-INF/classes
  2. JAR file in WEB-INF/classes/lib and class files in WEB-INF/classes
  3. Both in WEB-INF/classes
  4. Both in WEB-INF
  5. JAR file in WEB-INF/jars and class files in WEB-INF/classes

4 . Write the name of the deployment descriptor tag that allows you to write a description for a element? Please do not add angle brackets?

5 . Which of the following statements are correct?

  1. Authorization means determining whether one has access to a particular resource or not
  2. Authentication means determining whether one has access to a particular resource or not
  3. Authentication means proving whether one is what one claims to be
  4. Data Integrity means that the data is not modified in transit between the sender and the receiver
  5. Data Integrity means that the data cannot be viewed by anybody other than it’s intended recipient

6 . Your web application named “FWorks” uses SpecialMath.class. This is an unbundled class and is not contained in any jar file. Where will you keep this class file?

  1. FWorks/WEB-INF
  2. FWorks/WEB-INF/classes
  3. FWorks/WEB-INF/lib/classes
  4. FWorks/classes
  5. FWorks/WEB-INF/lib

7 . Which jsp tag can be used to retrieve a property of a bean?

  1. jsp:useBean
  2. jsp:useBean.property
  3. jsp:useBean.getProperty
  4. jsp:getProperty
  5. jsp:property

8 . Associate the events with appropriate listener interface? Drag and drop the matching listener?

session is activated or passivated
session is timed out
an attribute is replaced in the session
a session is created

Choose the one below:

  1. HttpSessionListener
  2. HttpSessionBindingListener
  3. HttpSessionActivationListener
  4. None of these

9 . Given the code of doGet() method of a servlet (see exhibit). The data should be sent to the client only if loginUser() returns a non null userid. Otherwise a status of SC_FORBIDDEN should be sent. What can be placed at //1 to fulfill this requirement?

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException


   String userId = loginUser(req); //this method takes the credentials
                             from the request and logs in the user.

   if(userId == null)


      // 1 Should send SC_FORBIDDEN




     PrintWriter out = response.getWriter();

     generateAndPublishData(out); //this method writes appropriate date to out.



Choose the one below:

  1. req.getRequestDispatcher(“errorpage.jsp”).dispatch(req, res, HttpServletResponse.SC_FORBIDDEN)
  2. throw new ServletException(HttpServletResponse.SC_FORBIDDEN);
  3. res.setStatus(HttpServletResponse.SC_FORBIDDEN);
  4. res.sendError(HttpServletResponse.SC_FORBIDDEN, “You are not authorized.”);
  5. res.sendError(HttpServletResponse.SC_FORBIDDEN);

10 . Which of the following elements of web.xml affect the whole web application instead of a specific servlet?

  1. content-type
  2. init-param
  3. listener
  4. application
  5. app-config

11 . Which of the following statements regarding action are correct?

  1. It must have an ‘id’ attribute
  2. If ‘beanName’ attribute is present, ‘type’ must also be present
  3. It must have a ‘scope’ attribute
  4. If ‘class’ attribute is present, ‘type’ must also be present

12 . Identify the implicit objects available to EL expressions?

  1. requestScope
  2. application
  3. header
  4. page
  5. pageScope
  6. pageContext

13 . Populate the blanks with appropriate examples given in the options?

custom tag

Choose the one below:

14 . Which of the following XML fragments correctly defines a role named “manager” in web.xml?


2.<security-role rolename=manager></security-role>



Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4

15 . Which of the following statements is correct regarding HttpSessionBindingListener interface?

  1. The valueBound() method is called BEFORE the object becomes accessible through HttpSession.getAttribute()
  2. The valueUnbound() method is called BEFORE the object is removed from the HttpSession
  3. The valueReplaced() method is called BEFORE the object is replaced with another object in the session
  4. None of these

16 . Consider the following HTML code. Which method of MyFirstServlet will be invoked when you click on the url shown by the page?



  <a href="/myapp/servlet/MyFirstServlet">Make me say Hello World!</a>



Choose the one below:

  1. doGet
  2. doGET
  3. post
  4. doPost
  5. doPOST

17 . Your jsp page connects to the database and retrieves the data. It also formats the data and displays it to the client.Any of these operations can throw exceptions but you do not want to catch them all in this page and so you have written another jsp page that is meant to handle any kind of exceptions. How would you associate that error page named “error.jsp” with this page?

  1. Add in this page
  2. Add in this page
  3. Add in error.jsp
  4. Add in error.jsp

18 . You have to send a gif image to the client as a response to a request. How will you acquire the ‘out’ variable to do this?

  1. PrintWriter out = response.getPrintWriter();
  2. PrintWriter out = response.getWriter();
  3. FileOutputStream out = response.getServletOutputStream();
  4. ServletOutputStream out = response.getOutputStream();
  5. ServletOutputStream out = response.getServletOutputStream(“image/gif”);

19 . Which of the given statements are correct regarding the following JSP page code?

<jsp:useBean id="mystring" class="java.lang.String" />

<jsp:setProperty name="mystring" property="*" />


Assume that the request for this page contains a parameter mystring=hello
Choose the one below:

  1. It will print “”
  2. It will print “hello”
  3. It will not compile
  4. It will throw exception at runtime

20. Select the correct sequence of actions that a servlet container performs before servicing any request?

  1. Instantiate listeners defined in the deployment descriptor
  2. Initialize filters defined in the deployment descriptor
  3. Initialize servlets that are set to load on startup
  4. Call the contextInitialized method on the listeners implementing ServletContextListener interface

21 . Which of the following is a valid life cycle event listener interface but is NOT configured in the web.xml?

  1. HttpSessionListener
  2. SessionActivationListener
  3. HttpSessionBindingListener
  4. ContextAttributeListener
  5. SessionAttributeListener

22 . How can you retrieve the data sent by the FORM displayed by following HTML page code?



  <form action="/myapp/SaveServlet" method="POST">

    <input type="file" name="name">

    <input type="submit" value="POST">




Choose the one below:

  1. request.getParameter(“name”);
  2. request.getAttribute(“name”);
  3. request.getInputStream();
  4. request.getReader();
  5. request.getFileInputStream();


1 : 3 is correct.

2 : 1 & 2 is correct.

3 : 1 is correct.

4 : description or .

5 : 1,3 & 4 is correct.

6 : 2 is correct.

7 : 4 is correct.

8 :
session is activated or passivated – 3 is correct.
session is timed out – 1 & 2 is correct.
an attribute is replaced in the session – 4 is correct.
a session is created – 1 is correct.

9 : 3,4 & 5 is correct.

10 : 3 is correct.

11 : 1 & 2 is correct.

12 : 1,3,5 & 6 is correct.

13 :
comment – 5 is correct.
directive – 4 is correct.
declaration – 6 is correct.
scriptlet – 3 is correct.
custom tag – 1 is correct.
expression – 2 is correct.

14 : 4 is correct.

15 : 1 is correct.

16 : 1 is correct.

17 : 2 & 3 is correct.

18 : 4 is correct.

19 : 1 is correct.

20 : 1,2,3 & 4 is correct.

21 : 3 is correct.

22 : 3 & 4 is correct.



About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind


Please support the site
By clicking any of these buttons you help our site to get better