1 . Consider the following code:
public void doGet(HttpServletRequest req, HttpServlerResponse res) { PrintWriter out = res.getWriter(); out.println("Unable to find resource."); //1 response.sendError(404); }
Which of the following lines, when inserted at //1, will ensure that an IllegalStateException is NOT thrown?
Choose the one below:
- res.clear();
- res.empty();
- res.remove();
- if(!res.isCommitted())
- if( res.getStatus() != res.COMMITTED)
2 . 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.*”%>
3 . Consider the following contents for two JSP files:
In file companyhome.jsp: <html><body> Welcome to ABC Corp! <jsp:include page="companynews.jsp" /> </body></html> <%@ page errorPage="simpleerrorhandler.jsp" %>
In file companynews.jsp: <%@ page errorPage="advancederrorhandler.jsp" %> <h3>Todays News</h3>
Choose the one below:
- When companyhome.jsp is requested, the output will contain “welcome…” as well as “Todays News”
- companyhome.jsp will not compile
- companynews.jsp will not compile
- Both the files will compile but will throw an exception at runtime
- None of these
4 . Which HTTP method is used in FORM based Authentication?
- POST
- GET
- FORM
- HEAD
5 . Consider the following code snippets. What will be displayed on the browser when a GET request is sent to FirstServlet assuming that the buffer is large enough to hold all the data before sending the data to the client?
In the doGet() of FirstServlet: PrintWriter out = response.getWriter(); out.println("<html><body>Page 1"); RequestDispatcher rd = response.getRequestDispatcher("SecondServlet"); rd.forward(request, response);
In the doGet() of SecondServlet: PrintWriter out = response.getWriter(); out.println("<br>Page 2</body></html>");
Choose the one below:
- Only Page1
- Only Page2
- Page1 and Page2
- IllegalStateException at Runtime
6 . Which of the given options are equivalent?
- <% Hashtable ht = new Hashtable(); %>
- <%= Hashtable ht = new Hashtable() %>
- <jsp:scriptlet>Hashtable ht = new Hashtable();</jsp:scriptlet>
- <jsp:code>Hashtable ht = new Hashtable();</jsp:code>
- <jsp:scriptlet>Hashtable ht = new Hashtable()</jsp:scriptlet>
7 . When a session becomes invalid, which method is invoked on a session attribute implementing an appropriate interface?
- sessionInvalidated() of HttpSessionListener
- sessionDestroyed() of HttpSessionListener
- valueUnbound() of HttpSessionAttributeListener
- valueUnbound() of HttpSessionBindingListener
- valueUnbound() of HttpSessionListener
8 . 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?
- Add <%@errorPage=”error.jsp”%> in this page
- Add <%@page errorPage=”error.jsp”%> in this page
- Add <%@page isErrorPage=”true”%> in error.jsp
- Add <%@isErrorPage=”true”%> in error.jsp
9 . Consider the HTML code shown in the exhibit. Which of the following method calls can retrieve the “email” value sent from the browser?
<html><body> <form action="/myapp/servlet/EmailCatcherServlet"> Please enter your email: <input type="text" name="email"> <input type="submit"> </form> </body></html>
Choose the one below:
- getParameter(“email”) of ServletRequest
- getParameterValues(“email”) of ServletRequest
- getField(“email”) of HttpServletRequest
- getFormValue(“email”) of HttpServletRequest
- getParameters(“email”) of HttpServlet
10 . What will be the output?
<% { %> <jsp:useBean id="sb" class="java.lang.StringBuffer" /> sb.append("Hello"); <% } %> <%=sb%>
Choose the one below:
- It will print null
- It will print “Hello”
- It will not compile because <jsp:useBean> cannot be used inside a block
- It will not compile because StringBuffer is not a bean
- None of these
11 . Which HTTP method would you use to test the validity, accesibility, or modification time of a hyperlink?
- GET
- POST
- HEAD
- OPTIONS
- PUT
12 . A function has been defined in a tag library descriptor as follows:
<taglib> ... <function> <name>transform</name> <function-class>com.enthu.Functions</function-class> <function-signature>java.lang.String transformString(String)</function-signature> </function> ... </taglib>
Which of the following statements are correct?
Choose the one below:
- The Function class must have a method with the signature: public String transform(String arg);
- The Function class must have a function with the signature: public String transformString(String arg);
- The Function class may have any method of the type: public static XXX(String s); but the method name (ie. XXX) must be mapped to “transform” in web.xml
- The Function class may have any method of the type: public static XXX(String s); but the method name (ie. XXX) must be mapped to “transformString” in web.xml
- None of these
13 . In your report.jsp page, you want to include the output of “customer.jsp” page. But this page requires an additional parameter “custid”, which is not present in the request?
Which of the following code snippents does this?
1. <jsp:include page="customer.jsp" custid="1234"/> 2. <jsp:include page="customer.jsp"> <jsp:param> <name>custid</name> <value>1234</value> </jsp:param> </jsp:include> 3. <jsp:include page="customer.jsp" param-name="custid" param-value="1234"/> 4. <jsp:include page="customer.jsp"> <jsp:param name="custid" value="1234"/> </jsp:include>
Choose the one below:
- 1
- 2
- 3
- 4
14 . Which of the following statements are correct regarding the import tag of JSTL?
- The String value of the imported content can be made available for use outside of the tag in ‘var’ variable
- If the url contains a relative path, then the resource must exist in the same webapp
- import tag is more efficient than jsp:include action in the case when large amount of data is imported only to be given to another tag
- import tag is useful to convert URL when cookies are not supported by the client
- The content imported by the import tag can be made available only through a String object
15 . What are the implications of using the HTTP GET method for a form submission?
- You cannot pass binary data to the server
- You cannot send unlimited (or a lot of) data to the server
- You cannot send multiple values for one parameter to the server
- You can only reply with the HEADER information in the response
- The parameters will be appended to the URL as a query string
16 . It important to note that response of a POST request are never cached?
1. <taglib> <taglib-uri>/binomial</taglib-uri> <taglib-location>/WEB-INF/MathLib.tld</taglib-location> </taglib> 2. <taglib> <taglib-uri>/binomial</taglib-uri> <taglib-location>/WEB-INF/MathLib.jar</taglib-location> </taglib> 3. <taglib id="ABC_MATH_LIB"> <taglib-uri>/binomial</taglib-uri> <taglib-location>/WEB-INF/MathLib.tld</taglib-location> </taglib> 4. <taglib name="ABC_MATH_LIB"> <taglib-uri>/binomial</taglib-uri> <taglib-location>/WEB-INF/MathLib.jar</taglib-location> </taglib> 5. <taglib author="ABCINC"> <taglib-uri>/binomial</taglib-uri> <taglib-location>/WEB-INF/MathLib.tld</taglib-location> </taglib>
Choose the one below:
- 1
- 2
- 3
- 4
- 5
17 . Consider the following jsp code:
<html> <head> <% int k = 0; %> </head> <body> </body> </html>
In which method of the generated servlet will the declaration for ‘k’ be placed?
Choose the one below:
- This will not compile as you cannot put jsp code in the <head> element
- init()
- doGet()
- _jspService()
- constructor of the servlet
18 . Which event is received by a registered listener when an attribute is added to HttpSession?
- HttpSessionChangeEvent
- HttpSessionEvent
- HttpAttributeChangeEvent
- HttpSessionBindingEvent
- HttpAttributeEvent
19 . You are using a tag library with prefix “generator”, which supports a tag named “random”.This tag generates a random number and sets it to a variable named “value”?
Which of the following will output this value in the page?
Choose the one below:
- <generator:random>value</generator:random>
- <generator:random><%=value%></generator:random>
- <generator:random><% int value;%> <%=value%></generator:random>
- <generator:random><%getParameter(“value”)%></generator:random>
- None of the above
20 . Identify the techniques that can be used to implement ‘sessions’ if the client browser does not support cookies?
- Using Http headers
- Using https protocol
- Hidden form fields
- URL rewriting
- It cannot be done without cookie support
21 . Which of the following are valid JSP scriptlets?
- <% String uid = LoginHelper.login(request) %>
- <% String uid = LoginHelper.login(request); %>
- <%! String uid = LoginHelper.login(request) %>
- <%@ String uid = LoginHelper.login(request) %>
- <% for(int i=0; i< 10; i++) { out.println(i); } %>
22 . Consider the following web.xml code snippet:
<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
23 . 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?
Choose the one below:
- Data Access Object
- Business Deligate
- MVC
- Remote Method Invocation
- Transfer Object
24 . Which of the following directives are applicable ONLY for tag files?
- attribute
- variable
- page
- include
- import
- tag
25 . 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
26 . 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
27 . Identify the elements that help describe the attribute characteristics of a JSP custom tag in a TLD file?
- value
- name
- description
- rtexprvalue
- class
28 . 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
29 . Which of the following are valid values for the <transport-guarantee> element?
- CONFIDENTIAL
- INTEGRAL
- SECURE
- ENCRYPTED
- NONE
30 . Which method of ServletResponse would you use to set its content type?
- setParameter
- setHeader
- setAttribute
- setContentType
- None of the above
31 . 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”); E.getInitParameterValue(“dbname”);
Answers
1 : 4 is correct.
2 : 1 & 4 is correct.
3 : 1 is correct.
4 : 1 is correct.
5 : 2 is correct.
6 : 1 & 3 is correct.
7 : 4 is correct.
8 : 2 & 3 is correct.
9 : 1 & 2 is correct.
10 : 5 is correct.
11 : 3 is correct.
12 : 5 is correct.
Explanation: The Function class must have a method with signature: public static String transformString(String arg);
1 is incorrect. The method name must be the same as given in <function-signature> element.
2 is incorrect. Method name is correct but it should also be static.
13 : 4 is correct.
14 : 1 & 3 is correct.
15 : 1,2 & 5 is correct.
16 : 1,2 & 3 is correct.
17 : 4 is correct.
Explanation: This is a scriptlet and they always go inside the service method. ie. they are local to the request. 1 is incorrect. You can put JSP code anywhere
18 : 4 is correct.
Explanation:Following is the mapping of Listeners and their corresponding events.
HttpSessionListener : HttpSessionEvent
HttpSessionAttributeListener : HttpSessionBindingEvent
HttpSessionBindingListener : HttpSessionBindingEvent
Observe that both – HttpSessionAttributeListener and HttpSessionBindingListener, use HttpSessionBindingEvent.
19 : 2 is correct.
Explanation: 3 is incorrect It’ll give an exception saying value is not initialized!
20 : 2,3 & 4 is correct.
Explanation: 2 is correct Unlike HTTP, HTTPS uses SSL which is a stateful protocol.
3 is correct Remember that this is a non-standard and obsolete way.
This can only be done in an application specific way and requires that the page has a form.
21 : 2 & 5 is correct.
Explanation: 1 is incorrect. It does not have an ending semicolon
3 is incorrect. ! is used for declarations
4 is incorrect. @ is used for directives
22 : 1 is correct.
Explanation:4 is incorrect “supervisor” must be defined in the container. For example, in conf/tomcat-users.xml for Tomcat.
<security-role-ref> is used to map the role names hard coded in the servlet code to the actual role names defined in the servlet container.
23 : 3 is correct.
Explanation: The statement “…should provide XML and HTML interfaces…” means the same data is represented in different ways, therefore this is MVC.
24 : 1,2 & 6 is correct.
Explanation: 2 Valid only for tag files.
4 is incorret include directive is valid for regular JSP file also
5 is incorrect No such directive
25 : 1,2 & 5 is correct.
Explanation: 3 is incorrect This is done in HTTP Digest authentication mechanism
26 : 1 is correct.
Explanation: 1 is correct. A view (ie. the presentation of data) knows how to present the data and so can be replaced with another view without any impact on the data representation.
2 is incorrect. This allows plug and play between back end logic and the front end.
4 is incorrect. This allows plug and play between the data container (the DB) and data requestor.
27 : 2,3 & 4 is correct.
Explanation: An attribute element describes the attribute for a tag. Following is its definition.
<!ELEMENT attribute (name, required? , rtexprvalue?, type?, description?) >
28 : 3 is correct.
29 : 1,2 & 5 is correct.
30 : 4 is correct.
31 : 2 & 4 is correct.
Explanation: Calling getServletConfig() from the init() method returns the ServletConfig object for this servlet and calling getInitParameter(…) on the ServletConfig object returns the value of that parameter.