1 . Which constant is used to notify the container to reevaluate the custom tag’s body?
- EVAL_BODY
- EVAL_BODY_TAG
- EVAL_BODY_AGAIN
- EVAL_BODY_INCLUDE
2 . Which of the following statements regarding the JSP action tag are TRUE?
- Provides translation-time instructions to the JSP engine
- Can be used to declare a JavaBean instance in a JSP page
- Can be used to generate HTML code to embed an applet on a web page
- User-defined actions can be created
- Language is a standard JSP action
3 . Which of the following methods can be used to pass request to another servlet to handle by using the RequestDispatcher?
- request(ServletRequest req, ServletResponse res)
- include(ServletRequest req, ServletResponse res)
- dispatch(ServletRequest req, ServletResponse res)
- forward(ServletRequest req, ServletResponse res)
- process(ServletRequest req, ServletResponse res)
4 . What will be the output?
import javax.servlet.*; import javax.servlet.http.*; public class MyServlet extends GenericServlet { public void init() { //1 // Do something } public void init(ServletConfig config) //2 throws ServletException{ // Do something super.init(config); //3 } public void destroy() { //4 // Do something } public void service(ServletRequest req, //5 ServletResponse res) { // Do something } }
Choose the one below:
- Method //1 is necessary for this code to compile
- Method //2 is necessary for this code to compile
- Line //3 is necessary for this code to run
- Method //4 is necessary for this code to compile
- Method //5 is necessary for this code to compile
5 . Which pattern is normally used to encapsulate database SQL statement?
- Value Object
- Data Value Object
- Data Access Object
- Business Object
- Business Delegate
6 . For special character used in request URI, which of the following statements are correct?
- The ampersand (&) is used to separate name/value pairs
- The plus sign (+) is used to fill blank space
- The dash sign (-) is used to separate the name and value
- The percent sign (%) is used to start a query string
7 . Which statements are TRUE regarding the HttpServlet method doPost(HttpServletRequest req, HttpServletResponse res)?
- The method is called by the server (via the service method) to allow a servlet to handle a POST or PUT request
- The method is called by the server (via the service method) to allow a servlet to handle a POST or GET request
- The method is called by the server (via the service method) to allow a servlet to handle a POST request
- The method is called by the server (via the service method) to allow a servlet to handle a GET request
- The method allows the client to send data of unlimited length to the Web server a single time
- Operations requested through this method will NEVER have side effects
8 . Which of the following design pattern is used to reduce the amount of network traffic when transferring data?
- Model View Controller
- Data Access Object
- Business Delegate
- Value Object
9 . What is the authentication type which uses digital certificates as a security mechanism for a web based application?
10 . Which of the following method is used to retrieve the value associated to the init parameter defined in the init-param tag?
- getParameter(String name)
- getInitParameter(String name)
- getParameters()
- getInitParameterValue(String name)
11 . Which of the following statements are TRUE for the code given below?
int MAX_AGE; Cookie cookie = new Cookie("user", user); cookie.setMaxAge(MAX_AGE); response.addCookie(cookie);
Choose the one below:
- If MAX_AGE = 10; the cookie will expire after 10 seconds
- If MAX_AGE = 10; the cookie will expire after 600 seconds
- If MAX_AGE = 0; the cookie will be deleted
- If MAX_AGE = -1; the cookie is not stored persistently
- If MAX_AGE = -1; the code will generate run-time error
12 . In which directory you will most likely find the file myBaseUtil.jar?
- example/WEB-INF
- example/lib
- example/WEB-INF/lib
- example/WEB-INF/classes
- example/META-INF/lib
13 . Which of the following requirements are needed for FORM based authentication in a web based application?
- The session attribuite j_sessionid must be set
- The action or url must be j_security_check
- The name attribute for the username must be j_username
- The form method must be POST
- The name attribute for the password must be j_password
- Client side cookie must be enabled
14 . Which of the following deployment descriptor snippet will map the following request URI:
/tech/hello/index.jsp
for web application with context path as “tech”?
1. <servlet-mapping> <servlet-name>HelloWorldServlet</servlet-name> <url-pattern>/hello/*</url-pattern> </servlet-mapping> 2. <servlet-mapping> <servlet-name>HelloWorldServlet</servlet-name> <url-pattern>/hello/*.jsp</url-pattern> </servlet-mapping> 3. <servlet-mapping> <servlet-name>HelloWorldServlet</servlet-name> <url-pattern>/hello/index.jsp</url-pattern> </servlet-mapping> 4. <servlet-mapping> <servlet-name>HelloWorldServlet</servlet-name> <url-pattern>hello/*</url-pattern> </servlet-mapping>
Choose the one below:
- 1
- 2
- 3
- 4
15 . Which of the following methods will enable you to get one or more values from a request object?
- getParameter(String name)
- getParameters(String name)
- getAllParameters()
- getParameterValues(String name)
- getAllAttributes()
16 . Is the following statement TRUE or FALSE?
The four methods for session management in the context of web-based application are: Cookie, HttpSession object, URL rewriting and Hidden value.
Choose the one below:
- True
- False
17 . Which of the following packages are implicitly imported in the JSP page?
- java.lang.*
- java.util.*
- javax.servlet.*
- javax.servlet.jsp.*
- javax.servlet.jsp.tagext.*
18 . Which of the following is NOT an authentication method used by a web container?
- BASIC
- DIGEST
- SSL
- FORM
19 . Which methods can be used for writing logging message to servlet log file?
- log(String msg)
- log(int code, String msg)
- log(String msg, Throwable t)
- log(int code, String msg, Throwable t)
20 . Which tag is used in web.xml to mark a web application to be suitable for running between multiple systems?
- multiple
- distributable
- resource-ref
- transferrable
- splitable
21 . Which of the following are VALID servlet error attributes?
- javax.servet.error.status_code
- javax.servet.error.exception
- javax.servet.error.uri
- javax.servet.error.message
- javax.servet.error.query
22. Which statement is TRUE about the following jsp code snippet?
<% String theKey = "key"; String theValue = "value"; session.removeAttribute(theKey); //1 %> session.setAttribute("<%= theKey %>", "<%= theValue %>"); //2 session.getAttribute("<%= theKey %>"); //3 <%= session.getAttribute(theKey) %> //4
Choose the one below:
- The code compiles but might have runtime NullPointerException at //1
- There will have compilation error at //2 and //3
- There will have output as null at //4
- There will have output as theValue at //4
23 . Which of the following are VALID taglib configuration?
1. <taglib> ... <tag> <name>myTag</name> <tag-class>MyTag</tag-class> </tag> ... </taglib> 2. <taglib> ... <tag> <name>myTag</name> <tag-class>MyTag</tag-class> <body-content>SERVLET</body-content> </tag> ... </taglib> 3. <taglib> ... <tag> <name>myTag</name> <tag-class>MyTag</tag-class> <attribute> <name>name</name> </attribute> </tag> ... </taglib> 4. <taglib> ... <tag> <name>myTag</name> <tei-class>MyTagInfo</tei-class> <body-content>JSP</body-content> </tag> ... </taglib> 5. <taglib> ... <tag> <name>myTag</name> <tag-class>MyTag</tag-class> <tei-class>MyTagInfo</tei-class> <body-content>JSP</body-content> <attribute> <name>name</name> <required>true</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> </attribute> </tag> ... </taglib>
Choose the one below:
- 1
- 2
- 3
- 4
- 5
24 . Which of the following statement is FALSE regarding JSP page directive attributes default value?
- The session attribute has default value as true
- The buffer attribute has default value as 8kb
- The autoflush attribute has default value as false
- The isThreadSafe attribute has default value as true
- The isErrorPage attribute has default value as false
- The pageEncoding attribute has default value as ISO-8859-1
25 . Which of the following deployment descriptor tags are used for context level parameter initialization?
- param-name
- context-name
- context-param
- param-value
- context-value
- context-attrib
26 . What will be the output?
// Calling servlet: public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<HTML><BODY>"); out.println("I am calling others!"); RequestDispatcher rd= req.getRequestDispatcher("/MyServlet"); rd.include(req, res); out.println("</BODY></HTML>"); out.close(); } // Target servlet: protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { PrintWriter out = res.getWriter(); out.println("I am called by others!");
Choose the one below:
- “I am calling others!”
- “I am called by others!”
- Both “I am calling others!” and “I am called by others!”
- An IllegalStateException is thrown
- An IOException is thrown
27 . Which statement is NOT true about the SingleThreadModel interface?
- By implementing this interface it ensures that servlets handle only one
- If a servlet implements this interface, no two threads will execute concurrently in the servlet’s service method
- This interface has no methods
- The servlet container will ensure there will be only one instance of the servlet at a time if the servlet implements this interface
- Class variables are not protected by this interface, but instance variables are protected
28 . Which of the following method is called upon the initialization of a servlet context?
- contextInitializing(ServletContextEvent e)
- contextInitial(ServletContext e)
- contextInitialize(ServletContext e)
- contextInitialize(ServletContextEvent e)
- contextInitialized(ServletContextEvent e)
29 . Which of the following statements are TRUE?
- XML equivalent for JSP expression <%= expression %> is <jsp:expression>expression</jsp:expression>
- XML equivalent for JSP scriptlet <% scriptlet %> is <jsp:scriptlet>scriptlet</jsp:scriptlet>
- XML equivalent for JSP declaration <%! declaration %> is <jsp:declaration>declaration</jsp:declaration>.
- XML equivalent for JSP include directive <%@ include file=”url” %> is <jsp:include file=”url”/>, where url must be relative
- XML equivalent for JSP page directive <%@ page buffer=”16kb” %> is <jsp:page buffer=”16kb”/>
30 . Please select Correct JSP useBean declaration methods?
- <jsp:useBean id=”user” beanName=”TestUser” type=”com.test.model.User” />
- <jsp:useBean id=”user” beanName=”TestUser” class=”com.test.model.User” />
- <jsp:useBean beanName=”TestUser” class=”com.test.model.User” />
- <jsp:useBean beanName=”TestUser” class=”com.test.model.User” />
- <jsp:useBean id=”user” type=”com.test.model.User” />
31 . Which statement is TRUE regarding the following code?
import javax.servlet.*; import javax.servlet.http.*; public class MyHttpServlet extends HttpServlet implements SingleThreadModel { StringBuffer bufferOne = new StringBuffer(); //1 static StringBuffer bufferTwo = new StringBuffer(); //2 protected void doGet(HttpServletRequest req, //3 HttpServletResponse res) throws java.io.IOException{ HttpSession session = req.getSession(); //4 res.setContentType("text/html"); java.io.PrintWriter out = res.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>This is my servlet!</title>"); out.println("</head>"); out.println("<body>"); out.println("</body>"); out.println("</html>"); out.close(); }
Choose the one below:
- Variable bufferOne at //1 is NOT thread-safe
- Variable bufferTwo at //2 is NOT thread-safe
- Both A and B
- Variable req at //3 is NOT thread-safe
- Variable session at //4 is NOT thread-safe
- Both D and E
32 . Select sample web application file listing with appropriate directory structure?
1. index.html /login.jsp /images/logo.gif /WEB-INF/web.xml /WEB-INF/lib/basic.jar /WEB-INF/classes/Test.class 2. /index.html /login.jsp /images/logo.gif /WEB-INF/web.xml /WEB-INF/jar/basic.jar /WEB-INF/classes/Test.class 3. /index.html /login.jsp /images/logo.gif /WEB-INF/web.xml /WEB-INF/classes/basic.jar /WEB-INF/classes/Test.class 4. /index.html /login.jsp /images/logo.gif /META-INF/web.xml /WEB-INF/jar/basic.jar /WEB-INF/classes/Test.class 5. /index.html /login.jsp /images/logo.gif /META-INF/web.xml /WEB-INF/lib/basic.jar /WEB-INF/classes/Test.class 6. index.html /images/logo.gif /WEB-INF/web.xml /WEB-INF/jsp/login.jsp /WEB-INF/lib/basic.jar /WEB-INF/classes/Test.class
Choose the one below:
- 1
- 2
- 3
- 4
- 5
- 6
33 . Which of the following data element will definitely be thread-safe?
- Local variables
- Instance variables
- Static variables
- Class variables
- Context attributes
34 . Select the correct order that JSP methods are invoked by servlet container?
- jspInit(), jspService(), jspDestroy()
- jspInit(), _jspService(), jspDestroy()
- _jspInit(), jspService(), _jspDestroy()
- _jspInit(), _jspService(), _jspDestroy()
35 . Which of the following element is not included in a URL?
- Client ip
- Protocol
- Server Name
- Query string
- Port name
36 . Which of the following listeners is notified when a session is initialized?
- HttpSessionBindingListener
- SessionBindingListener
- HttpSessionListener
- HttpSessionListener
- HttpSessionChangedListener
37 . Which of the following best describes the life cycle of a JSP?
1. JSP page is translated into a servlet code Servlet code is compiled Servlet is loaded into memory Servlet instance is created 2. JSP page is translated into a servlet code Servlet is loaded into memory Servlet code is compiled Servlet instance is created 3. JSP is compiled JSP is translated into a servlet code Servlet is loaded into memory Servlet instance is created 4. JSP is loaded into memory Servlet code is compiled Servlet instance is created Servlet is loaded into memory 5. JSP page is translated into a servlet code Servlet code is compiled Servlet instance is created Servlet is loaded into memory
Choose the one below:
- 1
- 2
- 3
- 4
- 5
38 . Please identify the three methods declared in javax.servlet.Filter?
- service
- init
- destroy
- filter
- doFilter
39 . Which of the following deployment descriptor segments are VALID for security-related configuration of a web application?
1. <login-config> <auth-method>FORM</auth-method> <login-config> <form-login-page>/login.jsp</form-login-page> <form-error-page>/error.jsp</form-error-page> </login-config> </login-config> 2. <security-role> <description>My description.</description> <role-name>Manager</role-name> </security-role> 3. <security-constraint> <web-resource-collection> <web-resource-name>SecureStuff</web-resource-name> <url-mapping>/servlet/secure</url-mapping> <http-method>POST</http-method> </web-resource-collection> </security-constraint> 4. <security-constraint> <auth-constraint> <role-name>Broker</role-name> </auth-constraint> </security-constraint> 5. <security-constraint> <web-resource-collection> <web-resource-name>SecureStuff</web-resource-name> </web-resource-collection> <auth-constraint> <role-name>Broker</role-name> </auth-constraint> </security-constraint>
Choose the one below:
- 1
- 2
- 3
- 4
- 5
40 . Based on the following information, please construct the full path for the servlet?
docbase = c:/temp/ context path = /test alias name = MyMail servlet-name = com.jiris.common.util.MailServlet url-pattern = /mail/*
Choose the one below:
- c:/temp/mail/com/jiris/common/util/MailServlet.class
- c:/temp/test/com/jiris/common/util/MailServlet.class
- c:/temp/mail/test/com/jiris/common/util/MailServlet.class
- c:/temp/test/mail/com/jiris/common/util/MailServlet.class
41 . The ServletContext object are accessible from which of the following objects?
- HttpServlet
- GenericServlet
- HttpSession
- ServletConfig
- ServletResponse
42 . Which of the following method is used to store object into a request object?
- addAttribute(String name, String obj)
- putAttribute(String name, Object obj)
- setAttribute(String name, String obj)
- setAttribute(String name, Object obj)
- addObject(String name, Object obj)
43 . Which request method will be invoked for the following code?
<html> <body> <form action=´/servlet/comment´> <p>Please provide your comment here:</p> <input type=´text´ size=´40´ name=´Comment´> <input type=´submit´ value=´Submit´> </form> </body> </html>
Choose the one below:
- GET
- POST
- HEAD
- TRACE
- PUT
44 . Which of the following method might be invoked more than one time?
- doStartTag()
- doInitBody()
- doAfterBody()
- doEndTag()
45 . Which of the following methods are used to send an error page to the client?
- log(String msg)
- log(String msg, Throwable t)
- sendError(int code)
- sendError(int code, String msg)
- sendError(int code, String msg, Throwable t)
46 . Which of the following requests should be performed by using a POST method?
- Inserting a record into a database
- Accessing a static page
- Retrieving an image
- Sending credit card number
- Searching record in a database
47 . Which of the following are Correct ways to define inactive period of 5 minutes of a session before the server invalidates it?
- <session-timeout>5</session-timeout>
- <session-timeout>300</session-timeout>
- session.setMaxInactiveInterval(5);
- session.setMaxInactiveInterval(300);
- session.invalidate(5);
48 . Which are the two mandatory attributes for JSP taglib directive?
- uri
- id
- name
- prefix
- value
- location
49 . A session can be invalidated by which of the following?
- After a default period of inactivity, say 30 minutes
- Client side user closes the browser
- After a specified period of inactivity, say 10 minutes
- Client side user machine crashes
- Explicitly invalidate a session through method calls
50 . What is the method declaration for the method used in the HttpServlet class that handles the HTTP GET request?
- doGet(ServletRequest req, ServletResponse res)
- getPage(ServletRequest req, ServletResponse res)
- doGet(HttpServletRequest req, HttpServletResponse res)
- service(HttpServletRequest req, HttpServletResponse res)
Answers
1 : 3 is correct.
Explanation: To notify the container to reevaluate the custom tag’s body, you must return a value of IterationTag.EVAL_BODY_AGAIN in the doAfterBody() method.
2 : 2,3 & 4 is correct.
Explanation: jsp:bean declares the use of a JavaBean instance in a JSP page.
jsp:plugin instructs the JSP engine to generate appropriate HTML code for embedding applets on a web page.
Custom tags (taglibs) allow user-defined actions to be created.
Answer 1 is incorrect because the action JSP tag provides request-time instructions to the JSP engine.
Standard action types : jsp:include, jsp:forward, jsp:useBean, jsp:setProperty, jsp:getProperty, jsp:plugin
3 : 2 & 4 is correct.
Explanation: You can use either forward(…) or include(…) method to pass the request to another servlet to handle. While for forward(…), the control is passing to target servlet, for include(…), the control is still with the current servlet.
4 : 3 & 5 is correct.
Explanation: You need to override the service() method when you extends GenericServlet.
You need to call super.init(config) if you override this method.
5 : 2 is correct.
Explanation: A Data Access Object pattern is used to encapsulate database access functions. By putting database-specific SQL code into a separate layer as DAO layer, it is easy to modify it without affecting business logic layer, thus increase code manageability.
6 : 1 & 2 is correct.
7 : 3 & 5 is correct.
8 : 4 is correct.
9 : Client-Cert.
Explanation: The correct answer is CLIENT-CERT which stands for client certificate. It requires the client to provide a digital certificate containing information about the issuer, signature, serial number, key type, etc
10 : 2 is correct.
11 : 1,3 & 4 is correct.
12 : 3 is correct.
13 : 2,3,4 & 5 is correct.
14 : 3 is correct.
15 : 1 & 4 is correct.
16 : 1 is correct.
17 : 1,3 & 4 is correct.
18 : 3 is correct.
19 : 1 & 3 is correct.
20 : 2 is correct.
21 : 1,2 & 4 is correct.
22 : 3 is correct.
23 : 1,3 & 5 is correct.
24 : 3 is correct.
25 : 1,3 & 4 is correct.
26 : 3 is correct.
27 : 4 is correct.
28 : 5 is correct.
29 : 1,2 & 3 is correct.
30 : 1,4 & 5 is correct.
31 : 2 is correct.
32 : 1 & 6 is correct.
33 : 1 is correct.
34 : 2 is correct.
35 : 1 is correct.
36 : 3 is correct.
37 : 1 is correct.
38 : 2,3 & 5 is correct.
39 : 2 & 5 is correct.
40 : 2 is correct.
41 : 1,3 & 4 is correct.
42 : 4 is correct.
43 : 1 is correct.
44 : 3 is correct.
45 : 3 & 4 is correct.
46 : 1 & 4 is correct.
47 : 1 & 4 is correct.
48 : 1 & 4 is correct.
49 : 1,3 & 5 is correct.
50 : 3 is correct.