1 . Consider the following web.xml code:
<servlet> <servlet-name>BankServlet</servlet-name> <servlet-class>com.abc.bankapp.BankServlet</servlet-class> <security-role-ref> <role-name>manager</role-name> <role-link>supervisor</role-link> </security-role-ref> </servlet>
Which of the following statements are correct?
Choose the one below:
- The servlet code should use “manager” as a parameter in request.isUserInRole() method
- The servlet code can use “manager” or “supervisor” as a parameter in request.isUserInRole() method
- The servlet code should use”supervisor” as a parameter in request.isUserInRole() method
- The role of “manager” must be defined in the servlet container
- None of these
2 . You are designing a complex webapp that uses multi tier architecture.The application must provide interfaces for HTML as well as XML and should be maintainable.Which design pattern would you use?
- Data Access Object
- Business Deligate
- MVC
- Remote Method Invocation
- Transfer Object
3 . Which of the following directives are applicable ONLY for tag files?
- attribute
- variable
- page
- include
- import
- tag
4 . Which of the following are correct about FORM based authentication mechanism?
- HTML FORM is used to capture the username and password of the user
- Password is transmitted as plain text
- Password is transmitted in an encrypted form
- Password is transmitted either in encrypted text or in plain text depending on the browser
- This mechanism can be used over HTTPS
5 . Which pattern allows you to replace the presentation logic without much impact on the data representation?
- Model View Controller
- Business Delegate
- Transfer Object
- Data Access Object
- Bimodal DataAccess
6 . Identify the elements that help describe the attribute characteristics of a JSP custom tag in a TLD file?
- value
- name
- description
- rtexprvalue
- class
7 . Select the correct return types for ServletContext.getResource() and ServletContext.getResourceAsStream() methods?
- java.io.Resource and java.io.InputStream
- java.io.Resource and java.io.BufferedInputStream
- java.net.URL and java.io.InputStream
- java.io.File and java.io.InputStream
- java.net.URL and java.io.FileInputStream
8 . What will be the output?
<html> <body> <% String a = "aaa"; %> <%! String a = "AAA"; %> <% String b = "bbb"; %> <%! String b = "BBB"; %> <% out.println(a+b); %> </body> </html>
Choose the one below:
- aaabbb
- aaaBBB
- AAAbbb
- AAABBB
- Compilation error!
9 . Which of the following are valid values for the <transport-guarantee> element?
- CONFIDENTIAL
- INTEGRAL
- SECURE
- ENCRYPTED
- NONE
10 . Write the parent element of <session-timeout> element?
11 . Consider the tag handler class shown in exhibit.What will be printed when the above tag is used as follows in a jsp page?
Hello <mylib:mytag> World!</mylib:mytag> public class MyTag extends TagSupport { public int doAfterBody() { try { pageContext.getOut().println("In doAfterBody()"); } catch(Exception e) { } return SKIP_BODY; } }
Choose the one below:
- Hello
- Hello World!
- Hello In doAfterBody() World!
- Hello In doAfterBody()
- None of the above
12 . Which of the following HTTP protocol methods is eligible to produce unintended side effects upon multiple identical invocations beyond those caused by single invocation?
- GET
- POST
- HEAD
- PUT
- OPTIONS
13 . Which method of ServletResponse would you use to set its content type?
- setParameter
- setHeader
- setAttribute
- setContentType
- None of the above
14 .
<jsp:useBean id="mybean" beanName="my.app.MyBean" class="my.app.MyBean" />
is a valid useBean declaration?
Choose the one below:
- True
- False
15 . Which of the following lines can be used to retrieve a servlet initialization parameter “dbname” from the init() method of a servlet?
public void init() { String dbname = //1 : Insert line here }
Choose the one below:
- getServletConfig().getParameter(“dbname”);
- getServletConfig().getInitParameter(“dbname”);
- getServletContext().getInitParameter(“dbname”);
- getInitParameter(“dbname”);
- getInitParameterValue(“dbname”);
16 . Consider the following description of a tag in a TLD?
<tag> <name>SmilyTag</name> <tag-class>com.enthuware.ctags.SmilyTag</tag-class> <description> Replaces emoticons such as :), :D, and 🙁 with images. </description> <body-content>tagdependent</body-content> <attribute> <name>name</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag>
Which of the following statements regarding the above tag are correct?
Choose the one below:
- It is an empty tag
- It may be used as an empty tag
- It must have a body
- It must implement BodyTag interface
- It may take an attribute named ‘name’.But if present,its value must be dynamic
17 . Which of the following jsp fragments will print all the parameters and their values present in a request?
1. <% Enumeration enum = request.getParameterNames(); while(enum.hasMoreElements()) { Object obj = enum.nextElement(); out.println(request.getParameter(obj)); } %> 2. <% Enumeration enum = request.getParameters(); while(enum.hasMoreElements()) { String obj = (String) enum.nextElement(); out.println(request.getParameter(obj)); } %> 3. <% Enumeration enum = request.getParameterNames(); while(enum.hasMoreElements()) { String obj = (String) enum.nextElement(); out.println(request.getParameter(obj)); } %> 4. <% Enumeration enum = request.getParameterNames(); while(enum.hasMoreElements()) { Object obj = enum.nextElement(); %> <%=request.getParameter(obj); %> <% } %> 5. <% Enumeration enum = request.getParameterNames(); while(enum.hasMoreElements()) { String obj = (String) enum.nextElement(); %> <%=request.getParameter(obj)%> <% } %>
Choose the one below:
- 1
- 2
- 3
- 4
- 5
18 . Which of the following statements are valid JSP directive?
- <%! int k = 10 %>
- <% int k = 10; %>
- <%=somevariable%>
- <%@ taglib uri=”http://www.abc.com/tags/util” prefix=”util” %>
- <%@ page language=”java” import=”com.abc.*”%>
19 . How can you ensure the continuity of the session while using HttpServletResponse.sendRedirect() method when cookies are not supported by the client?
- By using hidden parameters
- By enconding the redirect path with HttpServletResponse.encodeRedirectURL() method
- By using HttpSession.encodeURL() method
- By using HttpServletRequest.encodeURL() method
- By using HttpServletResponse.encodeURL() method
20 . Which of the following are valid implicit variables in a JSP page?
- error
- page
- this
- root
- context
21 . A Tag Handler implements BodyTag interface.How many times its doAfterBody method may be called?
- BodyTag does not support doAfterBody
- 0
- 1
- 0 or 1
- Any number of times
22 . You have configured a listener class (see exhibit) in web.xml of a web application?
Now, consider the following code for the doGet() method of a servlet for the same web application?
public void doGet(HttpServletRequest req, HttpServletResponse res) { System.out.println(this.getServletContext().getAttribute("key"); //2 }
Which option can be inserted at //1 in the listener code so that servlet code at //2 prints 100?
import javax.servlet.*; public class MyListener implements ServletContextListener { public void contextInitialized(ServletContextEvent sce) { Integer key = new Integer(100); // 1 Insert code here. } public void contextDestroyed(ServletContextEvent sce) { } }
Choose the one below:
- this.setAttribute(“key”, key);
- this.getServletContext().setAttribute(“key”, key);
- this.getContext().setAttribute(“key”, key);
- sce.getContext().setAttribute(“key”, key);
- sce.getServletContext().setAttribute(“key”, key);
23 . Which of the following interfaces declares the methods jspInit() and jspDestroy()?
- javax.servlet.jsp.JSP
- javax.servlet.jsp.JspServlet
- javax.servlet.jsp.JspPage
- javax.servlet.jsp.HttpJspPage
- javax.servlet.jsp.HttpJspServlet
24 . Which of the following statements are correct JSP directives?
- <%@ page %>
- <%! taglib uri=”http://www.abc.com/tags/util” prefix=”util” %>
- <% include file=”/copyright.html”%>
- <%@ taglib uri=”http://www.abc.com/tags/util” prefix=”util” %>
- <%$ page language=”java” import=”com.abc.*”%>
25 . Which of the following classes hides the implementation details and provides a standard API to the services provided by the servlet container to a jsp page?
- HttpSession
- Servlet
- JspPage
- ServletContext
- PageContext
26 . Which of the following are true regarding the parameters defined using the <context-param> element of a deployment descriptor?
- They are thread safe
- They are accessible from multiple threads simultaneously and from any servlet of the web application
- They can be modified using the setAttribute() method
- They can be modified using the setParameter() method
- They can be modified using the setInitParameter() method
27 . How can you explicitly expunge the session object?
- You cannot. It can only be expunged automatically after session timeout expires
- By calling invalidate() on session object
- By calling expunge() on session object
- By calling delete() on session object
- By calling finalize() on session object
28.You have declared a useBean tag as
<jsp:useBean id="man" class="animal.Human" scope="application"/>
In which type of object will this bean be kept?
Choose the one below:
- Servlet
- HttpSession
- ServletContext
- ServletConfig
- ApplicationContext
29 . Which of the following is a sensible way of sending an error page to the client in case of a business exception that extends from java.lang.Exception?
- Catch the exception and use RequestDispatcher to forward the request to the error page
- Don’t catch the exception and define the ‘exception to error-page’ mapping in web.xml
- Catch the exception, wrap it into ServletException and define the ‘business exception to error-page’ mapping in web.xml
- Catch the exception, wrap it into ServletException, and define the ‘ServletException to error-page’ mapping in web.xml
- Don’t do anything, the servlet container will automatically send a default error page
30 . Business delegate pattern should be used to enable communication between the JSP code and the enterprise javabeans?
Choose the one below:
- True
- False
Answers
1 : 1 is correct.
2 : 3 is correct.
3 : 1,2 & 6 is correct.
4 : 1,2 & 5 is correct.
5 : 1 is correct.
6 : 2,3 & 4 is correct.
7 : 3 is correct.
8 : 1 is correct.
9 : 1,2 & 5 is correct.
10 : session-config.
11 : 1 is correct.
12 : 2 is correct.
13 : 4 is correct.
14 : 2 is correct.
15 : 2 & 4 is correct.
16 : 2 & 4 is correct.
17 : 3 & 5 is correct.
18 : 4 & 5 is correct.
19 : 2 is correct.
20 : 2 & 3 is correct.
21 : 5 is correct.
22 : 5 is correct.
23 : 3 is correct.
24 : 1 & 4 is correct.
25 : 5 is correct.
26 : 1 & 2 is correct.
27 : 2 is correct.
28 : 3 is correct.
29 : 1 & 3 is correct.
30 : 1 is correct.