Quiz
Questões - Practice Test 1 ( OCWCD Certification )
Create a free account to finish this quiz
Save your progress and see your final score.
Already have an account? Sign in
Questions in this quiz (57)
1Identify the statements regarding CGI.
- ACGI programs are plataform dependent while Servlet are not
- BSevlet code is more secure than CGI
- CWith traditional CGI, a new process is started for each HTTP request while for Servlets a single instance serves multiple requests in different threads.
- DAll of above
- EOnly A
- FOnly B
- GOnly C
2The ProcessLoanApplication uses the following code for its business logic:
public class ProcessLoanApplication extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
try
{
//Connect to database and do the business operations
//XXXXXXXXXXX
}
catch(SQLException e)
{
throw new ServletException(e);
}
}
}
This Servlet is configured in a web application with the following descriptor:
<web-app>
<error-page>
<exception-type>java.sql.SQLException</exception-type>
<location>/erros/DBErrorMessage.html</location>
</error-page>
<web-app>
Which of the following is the behavior of the application when the database connection fails with an SQLException at the code XXXXXXXXXXX?- AThe application gets redirected to the DBErrorMessage.html
- BThe container sends a response to the browser with the status code as 500.
- CThe application fails to deploy as the deployment descriptor contains a invalide element
- DNone of the options
3Given a following JSP page:
<html>
<body>
HELLO <br>
<%
for (int k=0;k<2;k++)
{
%>
out.print("welcome"+k);
<%
}
%>
</body>
</html>
What will be generated when the above JSP page is accessed?- AHELLO welcome0welcome1
- BHELLO
- CHELLO out.print("welcome"+k); out.print("welcome"+k);
- DHELLO out.print("welcome"1); out.print("welcome"2);
4In case of Model View Controller (MVC) design pattern, which component plays the following roles?
Renders the models
Sends user gestures to controller
Allow controller to select view
Requests updates from models- Amodel
- Bview
- Ccontroller
- DIntercepting filter
5While declaring an EL function in a Tag Library Description (TLD), which of the following entities need to be specified as a fully qualified names?
- Aclass name
- Bargument types
- Creturn type
- DAll of the above
- ENone of the above
6Consider the Servlet and JSP code below. Which of the given choices (when placed at //XXX position) will achieve
the functionlity described below?
On invoking the Servlet as http://localhost:8080/servlet/AskMeServlet?exam=SCWCD, "Yes, its easier than SCJP!" should be printed.
Assume that the JSP and Servlet are placed in their respective directories on the web server.
import java.io.*;
import javax.servlet.*;
public class AskMeServlet extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
//XXX
}
}
//Answer.jsp
<html>
<body>
Yes, it's easier than SCJP!
</body>
</html>- Aif(req.getParameter("exam").equals("SCWCD")){res.sendRedirect("../Answer.jsp");}
- Bif(req.getParameter("exam").equals("SCWCD")){res.forward("../Answer.jsp");}
- Cif(req.getParameter("exam").equals("SCWCD")){res.Redirect("../Answer.jsp");}
- Dif(req.getParameter("exam").equals("SCWCD")){req.Redirect("../Answer.jsp");}
- Eif(req.getParameter("exam").equals("SCWCD")){req.forward("../Answer.jsp");}
- Fif(req.getParameter("exam").equals("SCWCD")){req.sendRedirect("../Answer.jsp");}
7if you want to apply Model View Controller (MVC) design pattern on a web application, which of the following will be the role most suited for a Java Server Page (JSP)?
- AModel
- BView
- CController
- DNone of the options
8Which of the following method is considered to be non idempotent by the HTTP 1.1 specification?
- APOST
- BHEAD
- CCHOICES
- DGET
- EDELETE
- FPUT
9Consider the following HTML form. It accepts the user's name in a text input field, and has a submit button.
//HelloByName.html
<html>
<body>
<form action="/servlet/HelloByName">
What's your name?<input type="text" name="name">
<p><input type="SUBMIT"/>
</form>
</body>
</html>
The following is the servlet invoked when the submit button of the form is clicked -
//HelloByName.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloByName extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
String name=req.getParameter("name");
PrintWriter out = res.getWriter();
out.println("<HTML>");
out.println("<body>");
out.println("Hello "+name+", I am the doGet method!!");
out.println("</body>");
out.println("</HTML>");
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
String name=req.getParameter("name");
PrintWriter out = res.getWriter();
out.println("<HTML>");
out.println("<body>");
out.println("I am the doPost method! I don't feel the need to say hello to you. "+name+" is a funny name in any case!");
out.println("</body>");
out.println("</HTML>");
}
What will be displayed in the browser when a name, say "Alfred", is entered in the text field on the form, and the submit button is clicked?- AAn HTML page displaying "Hello, Alfred, I am the doGet method!!"
- BAn HTML page displaying "I am the doPost method! I don't feel the need to say hello to you. Alfred is a funny name in any case!
- CCompile Time Error
- DA blank HTML page
10Which of the following ensure that the session never gets invalidated automatically? ( Select four choices )
- AInvoke HttpSession.setMaxInactiveInterval(0)
- BInvoke HttpSession.setMaxInactiveInterval(-1)
- CInvoke HttpSession.setSessionTimeOut(0)
- DSpecify a value of -1 for element in the the deployment descriptor
- EInvoke HttpSession.setSessionTimeOut(-1)
- FSpecify a value of 0 for element in the the deployment descriptor
11"Acme Stores" has developed a shopping application using Servlets and JSP technologies. The application offers a personalized shopping experience to the customers using HTTP Sessions. Some of the security conscious customers disabled cookies in their Internet browsers. What is the impact of this on the application?
- AZero impact; Http Sessions do not depend on cookies.
- BApplication code has to be rewritten to use URL rewriting.
- CThe servlet container can use SSL sessions to manage the Http Session.
- DThe servlet container can enable the cookies without user intervention.
12Given the following code where 'request' is an HttpServletRequest object:
HttpSession session = request.getSession();
Identify the correct statements for the session object.- AThe session is invalidated when the session times out
- BThe session is invalidated when session.sessionInvalidated() method is invoked.
- CThe session is invalidated when session.invalidated() method is invoked.
- DThe session cannot be invalidated manually.
13An Email web site uses cookies for storing the logged on user name so that on their next visit, only the password has to be entered. The server sets only one cookie and its name is "UserId". How does the LoginServlet verify the presence of this cookie? ( Select two choices )
- ACookie cookie[] = request.getCookies();
- BCookie cookie = request.getCookie("UserId");
- CCookies cookies = request.getCookies();
- DEnumeration enum = request.getHeaders("UserId");
- ECookie cookie = request.getCookies();
- FEnumeration enum = request.getHeaders("Cookie");
14Given the following incomplete HTML file home.html:
<input type="text" name="balance" value="1500.50" />
Assuming req is a valid reference of HttpServletRequest interface. Which of the following are the correct ways for a user to retrieve the parameter value of salary in a servlet? ( Select four choices )- AString s1 = req.getParameter("balance");
- BObject s2 = req.getParameter("balance");
- CFloat s3 = Float.parseFloat(req.getParameter("balance"));
- Dfloat s4 = Float.parseFloat(req.getParameter("balance"));
- ENone of the options
15The deployment descriptor defines a property like this:
<web-app>
...
<context-param>
<param-name>webmaster</param-name>
<param-value>myaddress@mycompany.com</param-value>
<description>The email address of the administrator to whom questions and comments about this application should be addressed. </description>
</context-param>
...
</web-app>
How can you read the value of "webmaster" property?- AString webmaster = getServletContext().getInitParameter("webmaster");
- BObject webmaster = getServletContext().getParameter("webmaster");
- CString webmaster = getServletConfig().getInitParameter("webmaster");
- DObject webmaster = getServletConfig().getInitParameter("webmaster");
16A servlet is mapped in the web.xml of the web application "portal" as
<web-app>
...
<servlet-mapping>
<servlet-name>FileUpload</servlet-name>
<url-pattern>FileUpload</url-pattern>
</servlet-mapping>
...
</web-app>
Which of the following URLs would be served by this servlet?- Ahttp://server/portal/FileUpload
- Bhttp://server/portal/public_html/FileUpload
- Chttp://server/portal/FileUpload/mypage.jsp
- DNone of the options
17The web.xml of a web application looks like following
<web-app>
<servlet>
<servlet-name>MyServlet1</servlet-name>
<servlet-class>com.mycompany.MyServlet</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet>
<servlet-name>MyServlet2</servlet-name>
<servlet-class>com.mycompany.MyServlet</servlet-class>
<load-on-startup>-1</load-on-startup>
</servlet>
<servlet>
<servlet-name>MyServlet3</servlet-name>
<servlet-class>com.mycompany.MyServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
....
</web-app>
Which of the following statements is true about this application?- AThe application tries to load MyServlet1 first followed by MyServlet3.
- BMyServlet2 will not be loaded
- CThe loading order of MyServlet2 cannot be predicted from the web.xml.
- DThe application fails to load as load-on-startup cannot have negative values.
18Which of the following statements about error-page mechanism are valid?
- AThe error-page cannot be used when the Servlet calls sendError method on the response.
- BThe container extracts the wrapped exception using the ServletException.getRootException method.
- Cerror-page declarations using the exception-type element in the deployment descriptor must be unique to the class name of the exception-type
- Dif a servlet generates an error that is not handled by the error-page mechanism, the container must ensure to send a response with status code 500.
19Which of the following is the root of the deployment descriptor for a web application?
- Aweb-app
- Bweb-application
- Cweb-root
- Dapp-root
20Which of the following are valid attributes of @WebServlet annotation?
- AservletName
- BdisplayName
- CasyncSupported
- Dparams
- EinitParams
21Which annotation can be used on a servlet implementation to specify security constraints?
- AWebServlet
- BSecurity
- CWebSecurity
- DServletSecurity
- ESecurity Constraints can be defined only in web.xml
22A web application stores a unique key in the user's session as soon as he logs on. Which of the following methods can be used to find the attribute?
- APageContext.findAttribute(String name)
- BPageContext.getAttribute(String name)
- CPageContext.findAttribute(String name, int scope)
- DPageContext.getAttribute(String name, int scope)
23Which of the following statements are true about the "." and "[]" operators? ( Select four choices )
- AThe "." operator is used do access bean properties.
- BThe "." operator is used do access bean methods.
- CThe "[]" operator is used to access bean properties.
- DThe "." operator is a generalization of the "[]" operator.
- EThe "[]" operator is used to access objects stored in maps, lists and arrays.
- FThe "." operator cannot be used to access objects stored in lists and arrays.
24Identify the output of the following code fragment.
<%
session.setAttribute("varCents","20");
%>
$100.${varCents}- AA compilation error as $symbol is not escaped properly.
- BA ClassCastException will be thrown as varCents is a String.
- CThe page prints the value "$100.20"
- DThe page prints the value "$100.$20"
25Which of the following EL expressions will not result in a translation error?
- A${pageContext.sessionScope}
- B${pageContext.request}
- C${pageContext.exception}
- D${pageContext.pageScope}
- E${pageContext}
26Which of the following expressions would compute to the value 0?
- A${ 0 * (10 ne 100 ) }
- B${varDoesntExist1 + varDoesntExist2 }
- C${0 * 10 ne 100}
- D${varDoesntExist % 2 }
- E${0 % 2}
27Identify the output of the output of the following jsp page.
EL.jsp
-------------
<%
String s="2";
%>
${s+4}
-------------
Choose one answer.- A6
- B4
- C2 + 4
- DA compilation errorr since an integer addition is performed with a String parameter
28Consider the following code:
Which of the following lines of code should be place at line 6 to make this JSP work ( it should print "The value of i:1")- A<%@ int i=0; %>
- B<% int i; %>
- C<%! int i = 0; %>
- D< int i=0; />
29What will be the result of accessing the following JSP page, if the associated session does not have an attribute named str?
<%!
String str;
public void jspInit()
{
str=(String)session.getAttribute("str");
}
%>
The string is: <%= str %>- A"null" is printed
- BNullPointerException is thrown
- CCode does not compile
- DNone of the options
30A JSP page has the following directive:
//MyPage.jsp
<%@page pageEncoding="ISO-8859-1" session="false" errorPage="/error.jsp" %>
Which of the following JSP implicit objects are available in this page? ( Select three choices )- Apage
- Bsession
- Cexception
- Derror
- Eout
- Fapplication
- Gencoding
31Which of the following life cycle methods of a JSP file correspond to that of the Servlet.
- Ainit()
- B_jspDestroy()
- CjspInit()
- DjspService()
- EjspDestroy()
- Fdestroy()
- G_jspService()
32Which of the following XML elements do not have equivalent JSP syntax? ( Select two choices )
- Ajsp:directive.page
- Bjsp:directive.include
- Cjsp:param
- Djsp:expression
- Ejsp:text
- Fjsp:root
33Given the source code -
MyBean.java
public class MyBean implements java.io.Serializable
{
public String name="harry";
public String getName()
{
return name;
}
public void setName(String name)
{
this.name=name;
}
public MyBean(String name)
{
setName(name);
}
}
What will be the result of accessing this JSP page using http://localhost:8080/test/another.jsp?name1=Tom ?
<jsp:useBean id="beany" class="MyBean" scope="application" />
<jsp:setProperty name="beany" property="name" param="name1" />
<%=beany.getName() %>- APrints "Tom"
- BCompilation Error
- CPrints "Harry"
- DRuntime Exception is thrown
34Which of the following attributes can not go together in taglib directive? ( Select tow choices)
- Adefault
- Buri
- Cfiledir
- Dtagdir
- Eprefix
- Flocation
35Considering the following taglib definition, which of the choices are correct tag usages? ( Select two choices )
<taglib>
...
<tag>
<name>myTag</name>
<tag-class>java.whizlabs.com.scwcd.MyTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>myName</name>
<required>true</required>
</attribute>
<description>This is My Tag </description>
</tag>
</taglib>- A<tt:myTag myName="scwcd"> </tt:myTag>
- B<tt:myTag> </tt:myTag>
- C<tt:myTag myName="scwcd"> <% int i=0; %> </tt:myTag>
- D<tt:myTag> <% int i=0; %> </tt:myTag>
36Which JSTL core tag can be used to perform URL rewriting?
- Ac:include
- Bc:import
- Cc:getUrl
- Dc:url
- Ec:rewrite
37Which of the following JSTL fragments in the given choices is similar to the following code fragment?
<%
String name="whizlabs";
session.setAttribute(name);
%>- A<c:session var="name" value="whizlabs" />
- B<c:set var="name" value="whizlabs" />
- C<c:add var="name" scope="session" value="whizlabs" />
- DNone of the options
38Which of the following use of <jsp:useBean> tag for a JSP which uses MyPackage. MyBean JavaBean component are correct?
( Select two choices )- A<jsp:useBean id="MyPackage.MyBean" scope="page" />
- B<jsp:useBean id="MyBean" class="MyPackage.MyBean" />
- C<jsp:useBean id="MyBean" type="Bean1" scope="page" />
- D<jsp:useBean id="MyBean" beanName="MyPackage.MyBean" scope="page" />
- E<jsp:useBean id="MyBean" beanName="MyPackage.MyBean" className="MyBean" type="Bean1" scope="page" />
39Select the valid attribute of <jsp:getProperty>.
- Aname
- Bvalue
- Cproperty
- Did
- Escope
40"Acme News Inc" web site wants to display the latest world news at the bottom of the home page. This news item will be update by the editorial team every hour. Which of the following is the best code fragment to do the same?
- A<%@ include page="news.jsp" %>
- B<jsp:directive.include file="news.jsp" />
- C<jsp:include page="news.jsp" />
- D<%@ include file="news.jsp" %>
- E<jsp:include file="news.jsp" />
41Which of the following statements about the <c:param> core tag are true? ( Select two choices )
- AIt can be used only as a nested action tag of <c:import>, <c:url> and <c:redirect> tags.
- BThis tag has three attributes.
- CIf name is null, a NullPointerException is thrown.
- DIf value is null, it is processed as an empty value.
- EThe default attribute is opcional
42Which of the following statements about the servlet life cycle are true?
- AThe container loads the servlets as the container starts.
- BThe ServletConfig object passed to the init method is unique for each servlet declaration
- CThe container loads the servlet class using normal Java class loading facilities.
- DA servlet instance placed into service by a servlet container will at least handle one request in its lifetime.
- EThe container can reload the same instance even if destroy() method has been called on that instance.
43Which of the following are valid wrapper classes?
- AHttpResponseWrapper
- BServletRequestWrapper
- CHttpServletResponseWrapper
- DSessionWrapper
44Which of the following are valid Listener Interfaces? ( Select four )
- AHttpSessionListener
- BHttpSessionBindingListener
- CServletContextSessionListener
- DHttpSessionAttributeListener
- EHttpSessionActivationListener
- FHttpSessionPassivationListener
45A user has a requirement of reading the parameter from a flat file, which is required by all the components of the user's web-application. Which is the most appropriate method to be overridden to meet the specified requirement?
- AServletContext.contextInitialized()
- BServletContext.contextCreated()
- CHttpServletContextListener.contextCreated()
- DHttpServletContextListener.contextInitialized()
46A web application defines the following filter mappings:
<web-app>
...
<servlet-mapping>
<servlet-name>PaymentServlet</servlet-name>
<url-pattern>/Shopping/Payment/*</url-pattern>
</servlet-mapping>
<filter-mapping>
<filter-name>MyBankFilter</filter-name>
<servlet-name>PaymentServlet</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>CompressionFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>EncryptionFilter</filter-name>
<url-pattern>/Shopping/Payment/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>LogFilter</filter-name>
<url-pattern>/Shopping/Payment/*</url-pattern>
</filter-mapping>
...
</web-app>
A user accesses the web application using the URL http://server/portal/Shopping/Payment/PayByCreditCard.jsp
What would be the correct order of filters invoked by this URL?- AMyBankFilter, CompressionFilter, EncryptionFilter, LogFilter
- BCompressionFilter, EncryptionFilter, LogFilter, MyBankFilter
- CMyBankFilter, CompressionFilter, EncryptionFilter
- DMyBankFilter, EncryptionFilter, LogFilter, CompressionFilter
- ECompressionFilter, EncryptionFilter, LogFilter
- FFilters are not applied as servlet mapping takes the precedence over filter mapping
47A web application stores a CustomerInfo ( a user defined object ) na sessão. This object wants to get notified whenever it is added or removed from the session. Identify the false statements about the CustomerInfo object.
- AThe CustomerInfo has to implement HttpSessionBindingListener.
- BThe CustomerInfo has to be configured as a listener in the web.xml.
- CThe CustomerInfo has to implement HttpSessionAttributeListener.
- DAn object of type HttpSessionBindingEvent will be passed by the container in the notification methods.
48Which annotation can be used to specify the container managed entity manager?
- A@Resource
- B@PersistenceUnit
- C@PersistenceContext
- D@EntityManager
49Identify the correct statements regarding JDBC.
( Select three choices)- AJDBC provides an object oriented approach to databases.
- BJDBC drivers can be classified in 4 categories.
- CJDBC drivers can be classified in 3 categories.
- DJDBC provides a set of implementation-independent generic database access methods.
- EJDBC has features to optimizing network resources by employing connection pooling an implementing distributed transactions.
50Which API can be used to dispatch the request to a particuler url "url1" within the same Servlet Context which is different from the URI of the original request?
- AASyncContext.dispatch();
- BAsyncContext.dispatch("/url1");
- CAsyncContext.forward();
- DAsyncContext.include("/url1");
- ENone of the options
51In case an Asynchronous process times out, what will always happen?
- ARegistered AsyncListeners calling their onTimeout method.
- BContainer calling complete() on process.
- CListeners calling complete on process.
- DContainer dispatching an error page.
52Which of the following javascript object can be used to make asynchronous calls to a server?
- AXMLHttpRequest
- BXMLRequest
- CAJAXRequest
- DHttpRequest
- EAsyncXMLRequest
53Which deployment descriptor element can be used to define authorization?
- Auser-data-constraint
- Bauth-constraint
- Ctransport-guarantee
- Dlogin-config
- Eweb-resource-collection
54Which of the following authentication mechanisms are more secure than HTTP Basic authentication mechanism?
- AForm Based authentication
- BHTTPS Client authentication
- CHTTP Digest authentication
- DHTTP Base64 authentication
55Which of the following security issues can be defined by the <transport-guarantee> element in web.xml? ( Select two choices)
- AAuthentication
- BAuthorization
- CData Integrity
- DConfidentiality
56The <role-link> element of the deployment descriptor can be found immediately unde which of the following element?
- A<security-role>
- B<web-app>
- C<security-role-ref>
- D<servlet>
- E<security-constraint>
57A web-application defines its security constraint using the <security-constraint> element in its deployment descriptor.
What are the valid tags that could be used under this element to define the security constraint? ( Select three choices )- Aweb-resource-collection
- Buser-constraint
- Cauth-constraint
- Duser-data-constraint
- Erole-constraint
- Flogin-constraint
Information
- Description
- Concursos Públicos Desenvolvimento de Software (OCEJWCD 6 ONLINE COURSE) Quiz on Questões - Practice Test 1 ( OCWCD Certification ), created by Luis Felipe Guariento on 26/05/2018.
- Author
- Luis Felipe Guariento
- Language
- Português
- Views
- 0
- Tags
- Rating
- No ratings yet Rate this quiz