SCWCD(310-083) 51~100

Q: 51 You have created a web application that you license to real estate brokers.
The webapp is highly customizable including the email address of the broker, which is placed on the
footer of each page. This is configured as a context parameter in the deployment descriptor:
10. <context-param>
11. <param-name>footerEmail</param-name>
12. <param-value>joe@estates-r-us.biz</param-value>
13. </context-param>
Which EL code snippet will insert this context parameter into the footer?
A.<a href='mailto:${footerEmail}'>Contact me</a>
B.<a href='mailto:${initParam@footerEmail}'>Contact me</a>
C.<a href='mailto:${initParam.footerEmail}'>Contact me</a>
D.<a href='mailto:${contextParam@footerEmail}'>Contact me</a>
E.<a href='mailto:${contextParam.footerEmail}'>Contact me</a>
Answer: C
解析:value=getServletContext().getInitparameter("footerEmail")


Q: 52 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.${foo(5):func}
E.${func:foo("easy")}
F.${func:foo("3").name}
Answer: C, F
解析:EL的前缀为func,EL function(EL 函数)为foo(long parameter),返回Map对象,参数貌似没什么用

C.传递参数为2,返回整个Map对象。E.参数不正确。F.参数可以强制转换为long类型,name为Map对象的key值

Q: 53 Click the Exhibit button.
The Appliance class is a Singleton that loads a set of properties into a Map from an external data source.
Assume:

An instance of the Appliance class exists in the application-scoped attribute, appl
The appliance object includes the name property that maps to the value Cobia
The request-scoped attribute, prop, has the value name.

Which two EL code snippets will display the string Cobia? (Choose two.)


package com.example;
import java.util.*;
public class Appliance{
    private Map<String,String>props;
    public Appliance(){
        this.props=new HashMap<String,String()>;
        initialize();
    }
    public Map<String,String> getProperties(){
        return this.props;
    }
    private void initialize(){
        //code to load appliance properties
    }
}
A.${appl.properties.name}
B.${appl.properties.prop}
C.${appl.properties[prop]}
D.${appl.properties[name]}
E.${appl.getProperties().get(prop)}
F.${appl.getProperties().get('name')}
Answer: A, C

解析:上下文中有一个Appliance类对象名为appl,Appliance类有一个Map类型属性props,Map中存放key=name,value=Cobia,要获取cobia。

A.properties获取Map对象,再根据key值获得值cobia。

C.properties获取Map对象,再从请求域中名为prop的值name,name作为key值获得值cobia。

Q: 54 Squeaky Beans Inc. hired an outside consultant to develop their web
application. To finish the job quickly, the consultant created several dozen JSP pages that directly
communicate with the database. The Squeaky business team has since purchased a set of business objects
to model their system, and the Squeaky developer charged with maintaining the web application must
now refactor all the JSPs to work with the new system. Which pattern can the developer use to solve this
problem?
A.Transfer Object
B.Service Locator
C.Intercepting Filter
D.Business Delegate
Answer: D

解析:

D.Bussiness Delegate(业务代理 )减少表示层(JSPs)与逻辑层的耦合。

Q: 55 A developer is designing a web application that must verify for each
request:
The originating request is from a trusted network.
The client has a valid session.
The client has been authenticated.
Which design pattern provides a solution in this situation?
A.Transfer Object
B.Session Facade
C.Intercepting Filter
D.Template Method
E.Model-View-Controller
Answer: C

解析:用过滤器验证请求的安全

C.Intercepting Filter(拦截过滤器)采用拦截的方式为request和response提供前期或后期的处理。

Q: 56 The Squeaky Bean company has decided to port their web application to a
new J2EE 1.4 container. While reviewing the application, a developer realizes that in multiple places
within the current application, nearly duplicate code exists that finds enterprise beans. Which pattern
should be used to eliminate this duplicate code?
A.Transfer Object
B.Front Controller
C.Service Locator
D.Intercepting Filter
E.Business Delegate
F.Model-View-Controller
Answer: C

解析:

C.Servive Locator封装数据库访问(如:JNDI),减少重复代码。

Q: 57 Which two are characteristics of the Transfer Object design pattern?
(Choose two.)
A. It reduces network traffic by collapsing multiple remote requests into one.
B. It increases the complexity of the remote interface by removing coarse-grained methods.
C. It increases the complexity of the design due to remote synchronization and version control issues.
D. It increases network performance introducing multiple fine-grained remote requests which return very small
amounts of data.
Answer: A, C

解析:

A.将获取参数改为获取对象,减少颗粒度。

C.因为并发传送对象造成同步和版本控制的复杂度(并发)。

 

Q: 58 A developer has created a special servlet that is responsible for generating
XML content that is sent to a data warehousing subsystem. This subsystem uses HTTP to request these
large data files, which are compressed by the servlet to save internal network bandwidth. The developer
has received a request from management to create several more of these data warehousing servlets. The
developer is about to copy and paste the compression code into each new servlet. Which design pattern
can consolidate this compression code to be used by all of the data warehousing servlets?
A.Facade
B.View Helper
C.Transfer Object
D.Intercepting Filter
E.Composite Facade
Answer: D

解析:用拦截器处理请求的数据,使其能被其它servlet使用。

Q: 59 Which two are characteristics of the Service Locator pattern? (Choose two.)
A.It encapsulates component lookup procedures.
B.It increases source code duplication and decreases reuse.
C.It improves client performance by caching context and factory objects.
D.It degrades network performance due to increased access to distributed lookup services.
Answer: A, C

解析:

A.封装查找(lookup)方法

C.通过缓存和工厂对象改进客户端性能

B.刚好相反,D.利用统一的服务器访问方式,提高了网络的性能。



Q: 60 Click the Task button.
Given a servlet mapped to /control, place the correct URI segment returned as a String on the
corresponding HttpServletRequest method call for the URI: /myapp/control/processorder.

解析:

getServletPath:获取Servlet的路径(题中Servlet mapped to /control)。

getPathInfo:获取路径的额外信息。

getContext:获取根路径,即项目名。

 

Q: 61 You are creating a web form with this HTML:
11. <form action="sendOrder.jsp">
12. <input type="text" name="creditCard">
13. <input type="text" name="expirationDate">
14. <input type="submit">
15. </form>
Which HTTP method is used when sending this request from the browser?
A. GET
B. PUT
C. POST
D. SEND
E. FORM
Answer: A

解析:method有两个属性get和post,默认为get。

Q: 62 Given an HttpSession session, a ServletRequest request, and a
ServletContext context, which retrieves a URL to /WEB-INF/myconfig.xml within a web application?
A.session.getResource("/WEB-INF/myconfig.xml")
B.request.getResource("/WEB-INF/myconfig.xml")
C.context.getResource("/WEB-INF/myconfig.xml")
D.getClass().getResource("/WEB-INF/myconfig.xml")
Answer: C
解析:资源存放在上下文中(application),所以通过上下文获取。

Q: 63 Your company has a corporate policy that prohibits storing a customer's
credit card number in any corporate database. However, users have complained that they do NOT want
to re-enter their credit card number for each transaction. Your management has decided to use
client-side cookies to record the user's credit card number for 120 days. Furthermore, they also want to
protect this information during transit from the web browser to the web container; so the cookie must
only be transmitted over HTTPS.
Which code snippet creates the "creditCard" cookie and adds it to the out going response to be stored on
the user's web browser?
A. 10. Cookie c = new Cookie("creditCard", usersCard);
11. c.setSecure(true);
12. c.setAge(10368000);
13. response.addCookie(c);
B. 10. Cookie c = new Cookie("creditCard", usersCard);
11. c.setHttps(true);
12. c.setMaxAge(10368000);
13. response.setCookie(c);
C. 10. Cookie c = new Cookie("creditCard", usersCard);
11. c.setSecure(true);
12. c.setMaxAge(10368000);
13. response.addCookie(c);
D. 10. Cookie c = new Cookie("creditCard", usersCard);
11. c.setHttps(true);
12. c.setAge(10368000);
13. response.addCookie(c);
E. 10. Cookie c = new Cookie("creditCard", usersCard);
11. c.setSecure(true);
12. c.setAge(10368000);
13. response.setCookie(c);
Answer: C
解析:
setSecure设置cookie是否通过安全通道传送
setMagAge设置cookie的生命周期
addCookie给HttpServletResponse添加cookie

Q: 64 Given a header in an HTTP request:
X-Retries: 4
Which two retrieve the value of the header from a given HttpServletRequest request? (Choose two.)
A.request.getHeader("X-Retries")
B.request.getIntHeader("X-Retries")
C.request.getRequestHeader("X-Retries")
D.request.getHeaders("X-Retries").get(0)
E.request.getRequestHeaders("X-Retries").get(0)
Answer: A, B
解析:HttpServletRequest:
getHeader方法返回请求头文件字符串类型的值
getIntHeader方法返回请求头文件整形类型的值

Q: 65 For a given ServletResponse response, which two retrieve an object for
writing text data? (Choose two.)
A.response.getWriter()
B.response.getOutputStream()
C.response.getOutputWriter()
D.response.getWriter().getOutputStream()
E.response.getWriter(Writer.OUTPUT_TEXT)
Answer: A, B
解析:ServletResponse使用getWriter和getOutputStream方法写入内容

Q: 66 Which JSP standard action can be used to import content from a resource
called foo.jsp?
A.<jsp:import file='foo.jsp' />
B.<jsp:import page='foo.jsp' />
C.<jsp:include page='foo.jsp' />
D.<jsp:include file='foo.jsp' />
E.<jsp:import>foo.jsp</jsp:import>
F.<jsp:include>foo.jsp</jsp:include>
Answer: C
解析:没有jsp:import这个标签

<jsp:include page="">请求时加载page页面
<%@include file="">编译时与该页面编译为一个文件

Q: 67 Click the Task button.
A servlet context listener loads a list of com.example.Product objects from a database and stores that list
into the catalog attribute of the ServletContext object.
Place code snippets to construct a jsp:useBean standard action to access this catalog.


解析:从数据库中的com.example.Product对象中获取一个List属性(type="java.util.List),存放在ServletContext对象中的catalog属性。(id="catalog" scope="application" )

--Servlet的上下文servletContext即jsp的application)

 

 

Q: 68 A session-scoped attribute is stored by a servlet, and then that servlet
forwards to a JSP page. Which three jsp:useBean attributes must be used to access this attribute in the
JSP page? (Choose three.)
A.id
B.name
C.bean
D.type
E.scope
F.beanName
Answer: A, D, E
解析:
id:命名Bean变量
type:指定该对象的变量类型
scope:指定Bean的作用域

Q: 69 You need to create a JavaBean object that is used only within the current
JSP page. It must NOT be accessible to any other page including those that this page might import.
Which JSP standard action can accomplish this goal?
A.<jsp:useBean id='pageBean' type='com.example.MyBean' />
B.<jsp:useBean id='pageBean' class='com.example.MyBean' />
C.<jsp:makeBean id='pageBean' type='com.example.MyBean' />
D.<jsp:makeBean id='pageBean' class='com.example.MyBean' />
E.<jsp:useBean name='pageBean' class='com.example.MyBean' />
F.<jsp:makeBean name='pageBean' class='com.example.MyBean' />
Answer: B
解析:

<jsp:useBean id="" class="">

scope默认值是page

Q: 70 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.request.addHeader(new Cookie("username", "joe"))
E.request.addCookie(new Cookie("username", "joe"))
F.response.addCookie(new Cookie("username", "joe"))
G.response.addHeader(new Cookie("username", "joe"))
Answer: F
解析:HttpServletResponse通过addCookie方法添加cookie

Q: 71 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
Answer: A

解析:默认的method为GET

Q: 72 You are creating a servlet that generates stock market graphs. You want to
provide the web browser with precise information about the amount of data being sent in the response
stream. Which two HttpServletResponse methods will you use to provide this information? (Choose
two.)
A.response.setLength(numberOfBytes);
B.response.setContentLength(numberOfBytes);
C.response.setHeader("Length", numberOfBytes);
D.response.setIntHeader("Length", numberOfBytes);
E.response.setHeader("Content-Length", numberOfBytes);
F.response.setIntHeader("Content-Length", numberOfBytes);
Answer: B, F
解析:HttpServletResponse方法:
setContentLength(in tlen)
setIntHeader(java.lang.String name,int value)。

Q: 73 You need to retrieve the username cookie from an HTTP request. If this
cookie does NOT exist, then the c variable will be null. Which code snippet must be used to retrieve this
cookie object?
A.
10. Cookie c = request.getCookie("username");
B.
10. Cookie c = null;
11. for ( Iterator i = request.getCookies();
12. i.hasNext(); ) {
13. Cookie o = (Cookie) i.next();
14. if ( o.getName().equals("username") ) {
15. c = o;
16. break;
17. }
18. }
C.
10. Cookie c = null;
11. for ( Enumeration e = request.getCookies();
12. e.hasMoreElements(); ) {
13. Cookie o = (Cookie) e.nextElement();
14. if ( o.getName().equals("username") ) {
15. c = o;
16. break;
17. }
18. }
D.
10. Cookie c = null;
11. Cookie[] cookies = request.getCookies();
12. for ( int i = 0; i < cookies.length; i++ ) {
13. if ( cookies[i].getName().equals("username") ) {
14. c = cookies[i];
15. break;
16. }
17. }
Answer: D
解析:request.getCookies()返回的是Cookie[]类型

Q: 74 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();
E.request.getResourceAsStream(ServletRequest.REQUEST);
Answer: C
解析:

ServletRequest.getInputStream()返回ServletInputStream类型
ServletRequest.getReader()返回BufferedReader类型


Q: 75 Click the Exhibit button.
As a maintenance feature, you have created this servlet to allow you to upload and remove files on your
web server. Unfortunately, while testing this servlet, you try to upload a file using an HTTP request and
on this servlet, the web container returns a 404 status.
What is wrong with this servlet?
package com.example;
import javax.servlet.http.*;
public class MyWebDAV extends HttpServlet{
    private String resourceDirectory;
    public MyWebDAV(String resDir){
        this.resourceDirectory=resDir;
    }
    public void doPut(HttpServletRequest req,HttpServletResponse,resp){
        //store file to resourceDirectory(code not shown)
    }
    public void doDelete(HttpServletRequest req,HttpServletResponse resp){
        //remove file from resourceDirectory(code not shown)
    }
}
A. HTTP does NOT support file upload operations.
B. The servlet constructor must NOT have any parameters.
C. The servlet needs a service method to dispatch the requests to the helper methods.
D. The doPut and doDelete methods do NOT map to the proper HTTP methods.
Answer: B
解析:servlet的构造方法不能带参数(题中的构造方法缺super())

Q: 76 You have built a web application with tight security. Several directories of
your webapp are used for internal purposes and you have overridden the default servlet to send an
HTTP 403 status code for any request that maps to one of these directories. During testing, the Quality
Assurance director decided that they did NOT like seeing the bare response page generated by Firefox
and Internet Explorer. The director recommended that the webapp should return a more user-friendly
web page that has the same look-and-feel as the webapp plus links to the webapp's search engine. You
have created this JSP page in the /WEB-INF/jsps/error403.jsp file. You do NOT want to alter the
complex logic of the default servlet. How can you declare that the web container must send this JSP page
whenever a 403 status is generated?
A. <error-page>
<error-code>403</error-code>
<url>/WEB-INF/jsps/error403.jsp</url>
</error-page>
B. <error-page>
<status-code>403</status-code>
<url>/WEB-INF/jsps/error403.jsp</url>
</error-page>
C. <error-page>
<error-code>403</error-code>
<location>/WEB-INF/jsps/error403.jsp</location>
</error-page>
D. <error-page>
<status-code>403</status-code>
<location>/WEB-INF/jsps/error403.jsp</location>
</error-page>
Answer: C

解析:xml错误页面格式
<error-page>
<error-code>*</error-code>
<locaton>*</location>
</error-page>

Q: 77 You want to create a valid directory structure for your Java EE web
application, and your application uses tag files and a JAR file. Which three must be located directly in
your WEB-INF directory (NOT in a subdirectory of WEB-INF)? (Choose three.)
A.The JAR file
B.A directory called lib
C.A directory called tags
D.A directory called TLDs
E.A directory called classes
F. A directory called META-INF
Answer: B, C, E
解析:

B.lib(库)放置JAR文件

C.tags放置tag文件

E.classes放置class文件(src路径文件)

tld可以放在自定义的路径。

Q: 78 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);
E.response.sendErrorRedirect(302);
Answer: B
解析:

HttpServletResponse的sendError发送错误状态
HttpServletResponse的setStatus设置状态代码

HttpServletResponse的路径重定向

Q: 79 Which element of the web application deployment descriptor defines the
servlet class associated with a servlet instance?
A.<class>
B.<webapp>
C.<servlet>
D.<codebase>
E.<servlet-class>
F.<servlet-mapping>
Answer: E
解析:servlet通过<servlet-class>标签部署servlet类

Q: 80 Within the web application deployment descriptor, which defines a valid
JNDI environment entry?
A. <env-entry>
<env-entry-type>java.lang.Boolean</env-entry-type>
<env-entry-value>true</env-entry-value>
</env-entry>
B. <env-entry>
<env-entry-name>param/MyExampleString</env-entry-name>
<env-entry-value>This is an Example</env-entry-value>
</env-entry>
C. <env-entry>
<env-entry-name>param/MyExampleString</env-entry-name>
<env-entry-type>int</env-entry-type>
<env-entry-value>10</env-entry-value>
</env-entry>
D. <env-entry>
<env-entry-name>param/MyExampleString</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>This is an Example</env-entry-value>
</env-entry>
Answer: D
解析:
<eny-entry>用于在web.xml中配置资源,类型为java.lang下的标准类型。

C的类型错误,应该为java.lang.Integer。

Q: 81 Which three are described in the standard web application deployment
descriptor? (Choose three.)
A.session configuration
B.MIME type mappings
C.context root for the application
D.servlet instance pool configuration
E.web container default port bindings
F.ServletContext initialization parameters
Answer: A, B, F
解析:

C.上下文根路径.

D.servlet实例池不用配置。

E.web容器默认端口不用配置。

Q: 82 Which two are true regarding a web application class loader? (Choose two.)
A. A web application may override the web container's implementation classes.
B. A web application running in a J2EE product may override classes in the javax.* namespace.
C. A web application class loader may NOT override any classes in the java.* and javax.* namespaces.
D. Resources in the WAR class directory or in any of the JAR files within the library directory may be
accessed using the J2SE semantics of getResource.
E. Resources in the WAR class directory or in any of the JAR files within the library directory CANNOT be
accessed using the J2SE semantics of getResource.
Answer: C, D

解析:

web application 不会重写java类。

J2SE的getResource能读取文件。

Q: 83 Click the Task button.
Place the corresponding resources and directories in the proper web application deployment structure.
Answer: Check ExamWorx eEngine, Download from Member Center


解析:

路径没啥好说的,最好理解下各个文件夹存放的内容。

另外JSP files static content应该是jsp文件和静态文件(html什么的)

 

Q: 84 You are building JSP pages that have a set of menus that are visible based
on a user's security role. These menus are hand-crafted by your web design team; for example, the
SalesManager role has a menu in the file /WEB-INF/html/sales-mgr-menu.html. Which JSP code snippet
should be used to make this menu visible to the user?
A. <% if ( request.isUserInRole("SalesManager") ) { %>
<%@ include file='/WEB-INF/html/sales-mgr-menu.html' %>
<% } %>
B. <jsp:if test='request.isUserInRole("SalesManager")'>
<%@ include file='/WEB-INF/html/sales-mgr-menu.html' %>
</jsp:if>
C. <% if ( request.isUserInRole("SalesManager") ) { %>
<jsp:include file='/WEB-INF/html/sales-mgr-menu.html' />
<% } %>
D. <jsp:if test='request.isUserInRole("SalesManager")'>
<jsp:include file='/WEB-INF/html/sales-mgr-menu.html' />
</jsp:if>
Answer: A
解析:B、D的<jsp:if ...>,没有jsp:if标签

C.<jsp:include file=...>不正确,应该是<jsp:include page="">

Q: 85 For debugging purposes, you need to record how many times a given JSP is
invoked before the user's session has been created. The JSP's destroy method stores this information to a
database. Which JSP code snippet keeps track of this count for the lifetime of the JSP page?
A. <%! int count = 0; %>
<% if ( request.getSession(false) == null ) count++; %>
B. <%@ int count = 0; %>
<% if ( request.getSession(false) == null ) count++; %>
C. <% int count = 0;
if ( request.getSession(false) == null ) count++; %>
D. <%@ int count = 0;
if ( request.getSession(false) == null ) count++; %>
E. <%! int count = 0;
if ( request.getSession(false) == null ) count++; %>
Answer: A
解析:
<%!...%>JSP声明
<%...%>JSP Scriptlet
<%=...%>JSP 表达式

Q: 86 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>
Answer: A
解析:
XML标签表达的JSPX(JSP Document)声明为:<jsp:declaration>

Q: 87 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"); %>
Answer: C
解析:JSP 的application域相当于Servlet的ServletContext

Q: 88 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 %>
<b><%= i %></b>
Answer: C
解析:<scripting-invalid>表示不支持<%scripting%>语法

Q: 89 You are creating a new JSP page and you need to execute some code that
acts when the page is first executed, but only once. Which three are possible mechanisms for performing
this initialization code? (Choose three.)
A.In the init method.
B.In the jspInit method.
C.In the constructor of the JSP's Java code.
D.In a JSP declaration, which includes an initializer block.
E.In a JSP declaration, which includes a static initializer block.
Answer: B, D, E

解析:

A.jsp没有init方法,只有servlet有

C.jsp没有构造方法

D.动态块,初始时运行一次,相当于构造方法。

E.静态初始块,在运行时只执行一次。

 


Q: 90 You are writing a JSP that includes scriptlet code to declare a List variable
and initializes that variable to an ArrayList object. Which two JSP code snippets can you use to import
these list types? (Choose two.)
A. <%! import java.util.*; %>
B. <%! import java.util.List;
import java.util.ArrayList; %>
C. <%@ page import='java.util.List'
import='java.util.ArrayList' %>
D. <%@ import types='java.util.List'
types='java.util.ArrayList' %>
E. <%@ page import='java.util.List,java.util.ArrayList' %>
F. <%@ import types='java.util.List,java.util.ArrayList' %>
Answer: C, E
解析:JSP导入包<%@ import="">

Q: 91 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>
E. <my:errorProne>
<c:catch var="ex">
${ex.message}
</c:catch>
</my:errorProne>
Answer: B
解析:JSTL将可能产生异常的代码放在<c:catch></c:catch>中,如果其中代码发生异常,异常将被保存在var对象中

Q: 92 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>
Answer: D
解析:部署链接标签名和标签文件

<taglib>

<taglib-uri>**</taglib-uri>

<taglib-location>/**</taglib-location>

</taglib>

Q: 93 Assume that a news tag library contains the tags lookup and item:
lookup
Retrieves the latest news headlines and executes the tag body once for each headline.
Exposes a NESTED page-scoped attribute called headline of type com.example.Headline containing
details for that headline.
item
Outputs the HTML for a single news headline. Accepts an attribute info of type
com.example.Headline containing details for the headline to be rendered.Which snippet of JSP code
returns the latest news headlines in an HTML table, one per row?
A. <table>
<tr>
<td>
<news:lookup />
<news:item info="${headline}" />
</td>
</tr>
</table>
B. <news:lookup />
<table>
<tr>
<td><news:item info="${headline}" /></td>
</tr>
</table>
C. <table>
<news:lookup>
<tr>
<td><news:item info="${headline}" /></td>
</tr>
</news:lookup>
</table>
D. <table>
<tr>
<news:lookup>
<td><news:item info="${headline}" /></td>
</news:lookup>
</tr>
</table>
Answer: C
解析:(同27题)lookup获取新闻标题并执行标签体(<tr><td>)形成表格

Q: 94 Click the Exhibit button.
Assuming the tag library in the exhibit is imported with the prefix stock, which custom tag invocation
outputs the contents of the variable exposed by the quote tag?
<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sum.com/xml/ns/j2ee"
xmln:schemaLocation="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sum.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd" version="2.0">
    <tlib-version>1.0</tlib-version>               
    <short-name>stock</short-name>
    <uri>http://example.com/tld/stock</uri>
    <tag>
        <name>quote</name>
        <tag-class>com.example.QuoteTag</tag-class>
        <body-context>empty</body-context>
        <variable>
            <name-from-attribute>var</name-from-attribute>
            <scope>AT_BEGIN</scope>
        </variable>
        <attribute>
            <name>symbol</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>var</name>
            <required>true</required>
            <rtexprvalue>falsh</rtexprvalue>
        </attribute>
  </tag>

</taglib>
A. <stock:quote symbol="SUNW" />
${var}
B. ${var}
<stock:quote symbol="SUNW" />
C. <stock:quote symbol="SUNW">
${var}
</stock:quote>
D. <stock:quote symbol="SUNW" var="quote" />
${quote}
E. <stock:quote symbol="SUNW" var="quote">
<%= quote %>
</stock:quote>
Answer: D
解析:

<name-from-attribute>指的是创建的变量名称从属性name中来取得(变量名为var的值,即quote),

<rtexprvalue>表示的是属性是否接受scriptlet表达式的计算结果,默认情况下为false,即只能接受静态值,

标签设置变量值var=quote,${quote}用EL表达式输出quote变量。

Q: 95 Which two are true about the JSTL core iteration custom tags? (Choose
two.)
A. It may iterate over arrays, collections, maps, and strings.
B. The body of the tag may contain EL code, but not scripting code.
C. When looping over collections, a loop status object may be used in the tag body.
D. It may iterate over a map, but only the key of the mapping may be used in the tag body.
E. When looping over integers (for example begin='1' end='10'), a loop status object may not be used in the tag
body.
Answer: A, C

解析:

B.tag标签体没限制scripting。

D.key和value都能输出。

E.没限制。



Q: 96 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 var="resultMap" property="${results[0].name}"
value="${results[0].score}" />
E. <c:set target="${resultMap}" property="${results[0].name}"
value="${results[0].score}" />
Answer: E
解析:把bean的name和score用set存进HashMap中。

c:set有两种用法

设置作用域属性< c:set var = "user" scope = "session" value = "boy" />   

设置bean属性或Map值 :< c:set target = "${Map}" property = "Name" value = "Lily" scope = "session" />   property指定key值


Q: 97 You are creating a JSP page to display a collection of data. This data can be
displayed in several different ways so the architect on your project decided to create a generic servlet that
generates a comma-delimited string so that various pages can render the data in different ways. This
servlet takes on request parameter: objectID. Assume that this servlet is mapped to the URL pattern:
/WEB-INF/data.
In the JSP you are creating, you need to split this string into its elements separated by commas and
generate an HTML <ul> list from the data.
Which JSTL code snippet will accomplish this goal?
A. <c:import varReader='dataString' url='/WEB-INF/data'>
<c:param name='objectID' value='${currentOID}' />
</c:import>
<ul>
<c:forTokens items'${dataString.split(",")}' var='item'>
<li>${item}</li>
</c:forTokens>
</ul>
B. <c:import varReader='dataString' url='/WEB-INF/data'>
<c:param name='objectID' value='${currentOID}' />
</c:import>
<ul>
<c:forTokens items'${dataString}' delims=',' var='item'>
<li>${item}</li>
</c:forTokens>
</ul>
C. <c:import var='dataString' url='/WEB-INF/data'>
<c:param name='objectID' value='${currentOID}' />
</c:import>
<ul>
<c:forTokens items'${dataString.split(",")}' var='item'>
<li>${item}</li>
</c:forTokens>
</ul>
D. <c:import var='dataString' url='/WEB-INF/data'>
<c:param name='objectID' value='${currentOID}' />
</c:import>
<ul>
<c:forTokens items'${dataString}' delims=',' var='item'>
<li>${item}</li>
</c:forTokens>
</ul>
Answer: D
解析:(同30题)

<c:import var="保存目标文件的命名变量" url="目标文件">

<c:forEach var="命名变量"  items="被分字符串"  delims="分隔符" >







Q: 98 A web application contains a tag file called beta.tag in
/WEB-INF/tags/alpha. A JSP page called sort.jsp exists in the web application and contains only this JSP
code:
1. <%@ taglib prefix="x"
2. tagdir="/WEB-INF/tags/alpha" %>
3. <x:beta />
The sort.jsp page is requested.
Which two are true? (Choose two.)
A. Tag files can only be accessed using a tagdir attribute.
B. The sort.jsp page translates successfully and invokes the tag defined by beta.tag.
C. The sort.jsp page produces a translation error because a taglib directive must always have a uri attribute.
D. Tag files can only be placed in /WEB-INF/tags, and NOT in any subdirectories of /WEB-INF/tags.
E. The tagdir attribute in line 2 can be replaced by a uri attribute if a TLD referring to beta.tag is created and
added to the web application.
F. The sort.jsp page produces a translation error because the tagdir attribute on lines 1-2 specifies a directory
other than /WEB-INF/tags, which is illegal.
Answer: B, E
解析:

tagdir=标签文件实际位置,uri=标签文件映射位置。

Q: 99 What is the purpose of session management?
A. To manage the user's login and logout activities.
B. To store information on the client-side between HTTP requests.
C. To store information on the server-side between HTTP requests.
D. To tell the web container to keep the HTTP connection alive so it can make subsequent requests without the
delay of making the TCP connection.
Answer: C
解析:会话管理的目的是在服务器储存信息

Q: 100 The Squeaky Beans Inc. shopping application was initially developed for a
non-distributed environment. The company recently purchased the Acme Application Server, which
supports distributed HttpSession objects. When deploying the application to the server, the deployer
marks it as distributable in the web application deployment descriptor to take advantage of this feature.
Given this scenario, which two must be true? (Choose two.)
A. The J2EE web container must support migration of objects that implement Serializable.
B. The J2EE web container must use the native JVM Serialization mechanism for distributing HttpSession
objects.
C. As per the specification, the J2EE web container ensures that distributed HttpSession objects will be stored
in a database.
D. Storing references to Enterprise JavaBeans components in the HttpSession object might NOT be supported
by J2EE web containers.
Answer: A, D

解析:

B.HttpSession在分布式环境中,能跨JVM操作。

C.可能存在不同的数据库中。

D.分布式容器可能不支持非分布式组件。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值