j2ee考试题2

来源:互联网 发布:代办淘宝贷款骗局 编辑:程序博客网 时间:2024/06/05 22:49
考试题目答案正确答案分数Which statement is true about web container session management?
A. Access to session-scoped attributes is guaranteed to be thread-safe by the web container.
B. To activate URL rewriting, the developer must use the HttpServletResponse.setURLRewriting
method.
C. If the web application uses HTTPS, then the web container may use the data on the HTTPS
request stream to identify the client.
D. The JSESSIONID cookie is stored permanently on the client so that a user may return to the
web application and the web container will rejoin that session.
.C2...Which JSTL code snippet can be used to perform URL rewriting?
A. <a href='<c:url url="foo.jsp"/>' />
B. <a href='<c:link url="foo.jsp"/>' />
C. <a href='<c:url value="foo.jsp"/>' />
D. <a href='<c:link value="foo.jsp"/>' />
.C2...A developer has used this code within a servlet:
62. if(request.isUserInRole("vip")) {
63. // VIP-related logic here
64. }
What else must the developer do to ensure that the intended security goal is achieved?
A. Create a user called vip in the security realm
B. Define a group within the security realm and call it vip
C. Define a security-role named vip in the deployment descriptor
D. Declare a security-role-ref for vip in the deployment descriptor
.D2...Given this fragment in a servlet:
23. if(req.isUserInRole("Admin")) {
24. // do stuff
25. }
And the following fragment from the related Java EE deployment descriptor:
 <security-role-ref>
 <role-name>Admin</role-name>
 <role-link>Administrator</role-link>
 </security-role-ref>
 <security-role>
 <role-name>Admin</role-name>
 <role-name>Administrator</role-name>
 </security-role>
What is the result?
A. Line 24 can never be reached.
B. The deployment descriptor is NOT valid.
C. If line 24 executes, the user's role will be Admin.
D. If line 24 executes, the user's role will be Administrator.
.D2...Given this fragment from a Java EE deployment descriptor:
 <welcome-file>beta.html</welcome-file>
 <welcome-file>alpha.html</welcome-file>
And this request from a browser:
http://www.sun.com/SCWCDtestApp/register
Which statement is correct, when the container receives this request?
A. This deployment descriptor is NOT valid.
B. The container first looks in the register directory for beta.html.
C. The container first looks in the register directory for alpha.html.
D. The container first looks for a servlet mapping in the deployment descriptor.
.D2...Which EL expression evaluates to the request URI?
A. ${requestURI}
B. ${request.URI}
C. ${request.getURI}
D. ${pageContext.request.requestURI}
.D2...A developer is designing the presentation tier for a web application that relies on a complex
session bean. The session bean is still being developed and the APIs for it are NOT finalized.
Any changes to the session bean API directly impacts the development of the presentation tier.
Which design pattern provides a means to manage the uncertainty in the API?
A. View Helper
B. Front Controller
C. Composite View
D. Business Delegate
.D2...A developer is designing a multi-tier web application and discovers a need to hide the details of
establishing and maintaining remote communications from the client. In addition, because the
business and resource tiers are distributed, the application needs to minimize the inter-tier
network traffic related to servicing client requests. Which design patterns, working together,
address these issues?
A. Front Controller and Transfer Object
B. Front Controller and Service Locator
C. Business Delegate and Transfer Object
D. Business Delegate and Intercepting Filter
.C2...Given an HttpServletRequest request and HttpServletResponse response, which sets a cookie
"username" with the value "joe" in a servlet?
A. request.addCookie("username", "joe")
B. request.setCookie("username", "joe")
C. response.addCookie("username", "joe")
D. response.addCookie(new Cookie("username", "joe"))
.D2...Your web page includes a Java SE v1.5 applet with the following declaration:
11. <object classid='clsid:CAFEEFAC-0015-0000-0000-ABCDEFFEDCBA'
12. width='200' height='200'>
13. <param name='code' value='Applet.class' />
14. </object>
Which HTTP method is used to retrieve the applet code?
A. GET
B. PUT
C. POST
D. RETRIEVE
.A2...Given:
10. public void service(ServletRequest request,
11. ServletResponse response) {
12. ServletInputStream sis =
13. // insert code here
14. }
Which retrieves the binary input stream on line 13?
A. request.getWriter();
B. request.getReader();
C. request.getInputStream();
D. request.getResourceAsStream();
.C2...Given:
11. public class MyServlet extends HttpServlet {
12. public void service(HttpServletRequest request,
13. HttpServletResponse response)
14. throws ServletException, IOException {
15. // insert code here
16. }
17. }
and this element in the web application's deployment descriptor:
<error-page>
<error-code>302</error-code>
<location>/html/error.html</location>
</error-page>
Which, inserted at line 15, causes the container to redirect control to the error.html resource?
A. response.setError(302);
B. response.sendError(302);
C. response.setStatus(302);
D. response.sendRedirect(302);
.B2...Which element of the web application deployment descriptor defines the servlet class associated
with a servlet instance?
A. <class>
B. <webapp>
C. <servlet>
D. <servlet-class>
.D2...For manageability purposes, you have been told to add a "count" instance variable to a critical
JSP Document so that a JMX MBean can track how frequent this JSP is being invoked. Which
JSP code snippet must you use to declare this instance variable in the JSP Document?
A. <jsp:declaration>
int count = 0;
<jsp:declaration>
B. <%! int count = 0; %>
C. <jsp:declaration.instance>
int count = 0;
<jsp:declaration.instance>
D. <jsp:scriptlet.declaration>
int count = 0;
<jsp:scriptlet.declaration>
.A2...In a JSP-centric web application, you need to create a catalog browsing JSP page. The catalog is
stored as a List object in the catalog attribute of the webapp's ServletContext object. Which
scriptlet code snippet gives you access to the catalog object?
A. <% List catalog = config.getAttribute("catalog"); %>
B. <% List catalog = context.getAttribute("catalog"); %>
C. <% List catalog = application.getAttribute("catalog"); %>
D. <% List catalog = servletContext.getAttribute("catalog"); %>
.C2...Given the element from the web application deployment descriptor:
<jsp-property-group>
<url-pattern>/main/page1.jsp</url-pattern>
<scripting-invalid>true</scripting-invalid>
</jsp-property-group>
and given that /main/page1.jsp contains:
<% int i = 12; %>
<b><%= i %></b>
What is the result?
A. <b></b>
B. <b>12</b>
C. The JSP fails to execute.
D. <% int i = 12 %>
.C2...Assume the custom tag my:errorProne always throws a java.lang.RuntimeException with the
message "File not found."
An error page has been configured for this JSP page.
Which option prevents the exception thrown by my:errorProne from invoking the error page
mechanism, and outputs the message "File not found" in the response?
A. <c:try catch="ex"><my:errorProne /></c:try>
   ${ex.message}
B. <c:catch var="ex"><my:errorProne /></c:catch>
   ${ex.message}
C. <c:try><my:errorProne /></c:try><c:catch var="ex" />
   ${ex.message}
D. <c:try><my:errorProne /><c:catch var="ex" />
   ${ex.message}
   </c:try>
.B2...A JSP page contains a taglib directive whose uri attribute has the value dbtags. Which XML
element within the web application deployment descriptor defines the associated TLD?
A. <tld>
<uri>dbtags</uri>
<location>/WEB-INF/tlds/dbtags.tld</location>
</tld>
B. <taglib>
<uri>dbtags</uri>
<location>/WEB-INF/tlds/dbtags.tld</location>
</taglib>
C. <tld>
<tld-uri>dbtags</tld-uri>
<tld-location>/WEB-INF/tlds/dbtags.tld</tld-location>
</tld>
D. <taglib>
<taglib-uri>dbtags</taglib-uri>
<taglib-location>
/WEB-INF/tlds/dbtags.tld
</taglib-location>
</taglib>
.D2...Assume a JavaBean com.example.GradedTestBean exists and has two attributes. The attribute
name is of type java.lang.String and the attribute score is of type java.lang.Integer. An array of
com.example.GradedTestBean objects is exposed to the page in a request-scoped attribute
called results. Additionally, an empty java.util.HashMap called resultMap is placed in the page
scope.
A JSP page needs to add the first entry in results to resultMap, storing the name attribute of the
bean as the key and the score attribute of the bean as the value. Which code snippet of JSTL
code satisfies this requirement?
A. ${resultMap[results[0].name] = results[0].score}
B. <c:set var="${resultMap}" key="${results[0].name}"
value="${results[0].score}" />
C. <c:set var="resultMap" property="${results[0].name}">
${results[0].value}
</c:set>
D. <c:set target="${resultMap}" property="${results[0].name}"
value="${results[0].score}" />
.D2Which three web application deployment descriptor elements allow web components to gain
references to resources or EJB components? (Choose three.)
A. ejb-ref
B. jdbc-ref
C. resource-env-ref
D. resource-ref
.A,C,D .  .  . Which two actions protect a resource file from direct HTTP access within a web application?
(Choose two.)
A. Placing it in the /secure directory
B. Placing it in the /WEB-INF directory
C. Placing it in the /META-INF/secure directory
D. Creating a <web-resource> element within the deployment descriptor
.B,C .  .  . Given that www.example.com/SCWCDtestApp is a validly deployed Java EE web application and
that all of the JSP files specified in the requests below exist in the locations specified. Which two
requests, issued from a browser, will return an HTTP 404 error? (Choose two.)
A. http://www.example.com/SCWCDtestApp/test.jsp
B. http://www.example.com/SCWCDtestApp/WEB-INF/test.jsp
C.http://www.example.com/SCWCDtestApp/META-INF/test.jsp
D. http://www.example.com/SCWCDtestApp/Customer/test.jsp
 
.B,C .  .  . Which two about WAR files are true? (Choose two.)
A. WAR files must be located in the web application library directory.
B. WAR files must contain the web application deployment descriptor.
C.The web container must serve the content of any META-INF directory located in a WAR file.
D. The web container must allow access to resources in JARs in the web application library directory.
.B,D .  .  . Given an EL function foo, in namespace func, that requires a long as a parameter and returns a
Map, which two are valid invocations of function foo? (Choose two.)
A. ${func(1)}
B. ${foo:func(4)}
C. ${func:foo(2)}
D.${func:foo("3").name}
.C,D . ..A developer is designing a multi-tier web application and discovers a need to log each incoming
client request. Which two patterns, taken independently, provide a solution for this problem?
(Choose two.)
A. Transfer Object
B. Service Locator
C. Front Controller
D. Intercepting Filter
.C,D. HttpServletRequest类的getParameterNames()方法返回类型是String[]。 B
<form action="">,在form提交时是post请求。 B
session.getParameter("count")可以取出count属性 B
当一个servlet修改后,需要重启服务器 A
当一个JSP修改后,需要重启服务器? B
HttpServlet类的doGet()方法抛出ServletException和IOException A
一个页面中可以包含多个<%@ include %> A
HttpServletRequest类的getParameterValues()方法返回类型是String[]。 A
Bean的事件是java.util.EventObject的子类。 A
使用Servlet,我们可以编写服务器端和客户端程序。 B
Service()方法表示Servlet生命周期的结束。 B
ServletContext类的getRequestDispatcher()可以接受相对路径。 B
Servlet的生命周期分三个时期:装载Servlet 、创建一个Servlet实例、销毁。 A
J2EE容器包括的服务器端容器有Wed容器,EJB容器,Application Client容器。 B
Servlet程序的入口点是main() B
JDBC的主要任务是:与数据库建立连接、发送SQL语句、处理结果。 A
理论上,GET是 用于获取服务器信息并将其作为响应返回给客户端,POST是用于客户端把数据传送到服务器 。 A
组件是JavaEE应用的基本单元。JavaEE提供的组件主要包括三类:客服端组件、Web组件和EJB组件。 A
MVC设计模式的核心组成有模型、视图、控制器。 A
原创粉丝点击