SCWCD(310-083) 151~200

Q: 151 Click the Task button.
Place the code snippets in the proper order to construct the JSP code to include dynamic content into a
JSP page at request-time.
Answer: Check ExamWorx eEngine, Download from Member Center


解析:动态加载页面<jsp:include page=""/>

Q: 152 Given:
6. <% int[] nums = {42, 420, 4200};
7. request.setAttribute("foo", nums); %>
Which two successfully translate and result in a value of true? (Choose two.)
A.${true or false}
B.${requestScope[foo][0] > 500}
C.${requestScope['foo'][1] = 420}
D.${(requestScope['foo'][0] lt 50) && (3 gt 2)}
Answer: A, D
解析:
EL获取request中参数的方法${foo[0]}=${requestScope['foo'][0]}=42
==(是否相等)或者eq(equal)

Q: 153 Click the Exhibit button.
Given:
11. <% com.example.Advisor advisor = new com.example.Advisor(); %>
12. <% request.setAttribute("foo", advisor); %>
Assuming there are no other "foo" attributes in the web application, which three are valid EL
expressions for retrieving the advice property of advisor? (Choose three.)
package com.example;

public class Advisor{
    private String advice="take out the garbage";
    public String getAdvice(){
        return advice;
    }
    public void setAdvice(String advice){
        this.advice=advice;
    }
}

A.${foo.advice}
B.${request.foo.advice}
C.${requestScope.foo.advice}
D.${requestScope[foo[advice]]}
E.${requestScope["foo"]["advice"]}
F.${requestScope["foo"["advice"]]}
Answer: A, C, E
解析:EL获取request中的属性的方法:
${foo.advice}
${requestScope.foo.advice}
${requestScope["foo"]["advice"]}
另外:EL的foo.advice=advice(即foo).getAdvice()

Q: 154 You are creating an error page that provides a user-friendly screen
whenever a server exception occurs. You want to hide the stack trace, but you do want to provide the
exception's error message to the user so the user can provide it to the customer service agent at your
company. Which EL code snippet inserts this error message into the error page?
A.Message: <b>${exception.message}</b>
B.Message: <b>${exception.errorMessage}</b>
C.Message: <b>${request.exception.message}</b>
D.Message: <b>${pageContext.exception.message}</b>
E.Message: <b>${request.exception.errorMessage}</b>
F.Message: <b>${pageContext.exception.errorMessage}</b>
Answer: D
解析:
EL没有exception和request(有requestScopr)对象
EL用pageContext获得当前页面的javax.servlet.jsp.PageContext对象
exception只有getMessage没有getErrorMessage方法

Q: 155 You are building a dating web site. The client's date of birth is collected
along with lots of other information. You have created an EL function with the signature:
calcAge(java.util.Date):int and it is assigned to the name, age, in the namespace, funct. In one of your
JSPs you need to print a special message to clients who are younger than 25. Which EL code snippet will
return true for this condition?
A.${calcAge(client.birthDate) < 25}
B.${calcAge[client.birthDate] < 25}
C.${funct:age(client.birthDate) < 25}
D.${funct:age[client.birthDate] < 25}
E.${funct:calcAge(client.birthDate) < 25}
F.${funct:calcAge[client.birthDate] < 25}
Answer: C
解析:
EL函数calcAge标记为age,并且命名空间为funct
调用该函数:${funct:age(client.birthDate)}

Q: 156 Given:
11. <% java.util.Map map = new java.util.HashMap();
12. request.setAttribute("map", map);
13. map.put("a", "b");
14. map.put("b", "c");
15. map.put("c", "d"); %>
16. <%-- insert code here --%>
Which three EL expressions, inserted at line 16, are valid and evaluate to "d"? (Choose three.)
A.${map.c}
B.${map[c]}
C.${map["c"]}
D.${map.map.b}
E.${map[map.b]}
F.${map.(map.b)}
Answer: A, C, E
解析:${map.c}=${map["c"]} ${map.b}="c"

Q: 157 Assume the tag handler for a st:simple tag extends SimpleTagSupport. In
what way can scriptlet code be used in the body of st:simple?
A. set the body content type to JSP in the TLD
B. Scriptlet code is NOT legal in the body of st:simple.
C. add scripting-enabled="true" to the start tag for the st:simple element
D. add a pass-through Classic tag with a body content type of JSP to the body of st:simple, and place the
scriptlet code in the body of that tag
Answer: B
解析:scriptlet不能用在标签体内,虽然<body-content>有个scriptless选项,但是不能使用jsp脚本(scriptlet)。

Q: 158 Which statement is true if the doStartTag method returns
EVAL_BODY_BUFFERED ?
A.The tag handler must implement BodyTag.
B.The doAfterBody method is NOT called.
C.The setBodyContent method is called once.
D.It is never legal to return EVAL_BODY_BUFFERED from doStartTag.
Answer: C
解析:
A.实现BodyTag接口或者继承BodyTagSupport类(该类实现了BodyTag接口)
C.EVVAL_BODY_BUFFERED:申请缓冲区,由setBodyContent()函数得到的BodyContent对象来处理tag的body。

Q: 159 You are creating a library of custom tags that mimic the HTML form tags.
When the user submits a form that fails validation, the JSP form is forwarded back to the user. The
<t:textField> tag must support the ability to re-populate the form field with the request parameters from
the user's last request. For example, if the user entered "Samantha" in the text field called firstName,
then the form is re-populated like this:
<input type='text' name='firstName' value='Samantha' />
Which tag handler method will accomplish this goal?
A. public int doStartTag() throws JspException {
    JspContext ctx = getJspContext();
    String value = ctx.getParameter(this.name);
       if ( value == null ) value = "";
       JspWriter out = pageContext.getOut();
       try {
           out.write(String.format(INPUT, this.name, value));
    } (Exception e) { throw new JspException(e); }
    return SKIP_BODY;
    }
    private static String INPUT = "<input type='text' name='%s' value='%s' />";
B. public void doTag() throws JspException {
    JspContext ctx = getJspContext();
    String value = ctx.getParameter(this.name);
    if ( value == null ) value = "";
    JspWriter out = pageContext.getOut();
    try {
        out.write(String.format(INPUT, this.name, value));
    } (Exception e) { throw new JspException(e); }
    }
    private static String INPUT = "<input type='text' name='%s' value='%s' />";
C. public int doStartTag() throws JspException {
    ServletRequet request = pageContext.getRequest();
    String value = request.getParameter(this.name);
    if ( value == null ) value = "";
    JspWriter out = pageContext.getOut();
    try {
        out.write(String.format(INPUT, this.name, value));
    } (Exception e) { throw new JspException(e); }
    return SKIP_BODY;
    }
    private static String INPUT= "<input type='text' name='%s' value='%s' />";
D. public void doTag() throws JspException {
    ServletRequet request = pageContext.getRequest();
    String value = request.getParameter(this.name);
    if ( value == null ) value = "";
    JspWriter out = pageContext.getOut();
    try {
        out.write(String.format(INPUT, this.name, value));
    } (Exception e) { throw new JspException(e); }
    }
    private static String INPUT = "<input type='text' name='%s' value='%s' />";
Answer: C
解析:
JspContext是pageContext的父类,主要用于继承,并且与servlet无关。
doTag()方法为SimpleTagSupport中的方法,继承该类实现一些简单的自订标签。
doStartTag()方法为TagSupport中的方法,继承该类处理一些回传值的问题,可以获得pageContext属性。

Q: 160 Which two directives are applicable only to tag files? (Choose two.)
A. tag
B. page
C. taglib
D. include
E. variable
Answer: A, E
解析:
tag files中能使用的指令元素有taglib、include、tag、attribute、variable
只有tag files才有的就是tag和variable

Q: 161 The tl:taskList and tl:task tags output a set of tasks to the response and are
used as follows:
11. <tl:taskList>
12. <tl:task name="Mow the lawn" />
13. <tl:task name="Feed the dog" />
14. <tl:task name="Do the laundry" />
15. </tl:taskList>
The tl:task tag supplies information about a single task while the tl:taskList tag does the final output. The
tag handler for tl:taskList is TaskListTag. The tag handler for tl:task is TaskTag. Both tag handlers
extend BodyTagSupport.
Which allows the tl:taskList tag to get the task names from its nested tl:task children?
A. It is impossible for a tag handler that extends BodyTagSupport to communicate with its parent and child
tags.
B. In the TaskListTag.doStartTag method, call super.getChildTags() and iterate through the results. Cast each
result to a TaskTag and call getName().
C. In the TaskListTag.doStartTag method, call getChildTags() on the PageContext and iterate through the
results. Cast each result to a TaskTag and call getName().
D. Create an addTaskName method in TaskListTag. Have the TaskListTag.doStartTag method, return
BodyTag.EVAL_BODY_BUFFERED. In the TaskTag.doStartTag method, call super.getParent(), cast it to a
TaskListTag, and call addTaskName().
E. Create an addTaskName method in TaskListTag. Have the TaskListTag.doStartTag method, return
BodyTag.EVAL_BODY_BUFFERED. In the TaskTag.doStartTag method, call findAncestorWithClass() on the
PageContext, passing TaskListTag as the class to find. Cast the result to TaskListTag and call addTaskName().
Answer: D
解析:
BodyTagSupport的父类为TagSupport
TagSupport的getParent()方法可以获得父Tag
TagSupport的findAncestorWithClass()方法可以递归找到要找的Tag(BodyTagSupport没有该方法)

Q: 162 Click the Exhibit button.
Given:
10. <form action='create_product.jsp'>
11. Product Name: <input type='text' name='prodName'/><br/>
12. Product Price: <input type='text' name='prodPrice'/><br/>
13. </form>
For a given product instance, which three jsp:setProperty attributes must be used to initialize its
properties from the HTML form? (Choose three.)

package com.example;

public class Product{
    private String name;
    private double price;

    public Product(){
        this("Default",0.0);
    }
    public Product(String name,double price){
        this.name=name;
        this.price=price;
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public double getPrice(){
        return price;
    }
    public void setPrice(double price){
        this.price=price;
    }
}
A.id
B.name
C.type
D.param
E. property
F. reqParam
G. attribute
Answer: B, D, E
解析:
jsp:setProperty有四个属性:
name:指定属性所属的Bean(必需)
property:指定要设置的属性(必须)
param:指定请求的参数作为Bean的值(二选一)
value:指定Bean的属性的值

Q: 163 Given:
1. package com.example;
2.
3. public abstract class AbstractItem {
4. private String name;
...
13. }
Assume a concrete class com.example.ConcreteItem extends com.example.AbstractItem. A servlet sets a
session-scoped attribute called "item" that is an instance of com.example.ConcreteItem and then
forwards to a JSP page.
Which two are valid standard action invocations that expose a scripting variable to the JSP page?
(Choose two.)
A. <jsp:useBean id="com.example.ConcreteItem"
scope="session" />
B. <jsp:useBean id="item" type="com.example.ConcreteItem"
scope="session" />
C. <jsp:useBean id="item" class="com.example.ConcreteItem"
scope="session" />
D. <jsp:useBean id="item" type="com.example.ConcreteItem"
class="com.example.AbstractItem"
scope="session" />
Answer: B, C
解析:jsp:useBean:
class设置Bean的完整包名。
type设置该对象的变量的类型。

Q: 164 Your web application views all have the same header, which includes the
<title> tag in the <head> element of the rendered HTML. You have decided to remove this redundant
HTML code from your JSPs and put it into a single JSP called /WEB-INF/jsp/header.jsp. However, the
title of each page is unique, so you have decided to use a variable called pageTitle to parameterize this in
the header JSP, like this:
10. <title>${param.pageTitle}<title>
Which JSP code snippet should you use in your main view JSPs to insert the header and pass the
pageTitle variable?
A. <jsp:insert page='/WEB-INF/jsp/header.jsp'>
${pageTitle='Welcome Page'}
</jsp:insert>
B. <jsp:include page='/WEB-INF/jsp/header.jsp'>
${pageTitle='Welcome Page'}
</jsp:include>
C. <jsp:include file='/WEB-INF/jsp/header.jsp'>
${pageTitle='Welcome Page'}
</jsp:include>
D. <jsp:insert page='/WEB-INF/jsp/header.jsp'>
<jsp:param name='pageTitle' value='Welcome Page' />
</jsp:insert>
E. <jsp:include page='/WEB-INF/jsp/header.jsp'>
<jsp:param name='pageTitle' value='Welcome Page' />
</jsp:include>
Answer: E
解析:<jsp:include page="">动态加载页面
B的pageTile设置不对。

Q: 165 Click the Exhibit button.
Given the JSP code:
1. <%
2. pageContext.setAttribute( "product",
3. new com.example.Product( "Pizza", 0.99 ) );
4. %>
5. <%-- insert code here --%>
Which two, inserted at line 5, output the name of the product in the response? (Choose two.)
package com.example;

public class Product{
    private String name;
    private double price;

    public Product(){
        this("Default",0.0);
    }
    public Product(String name,double price){
        this.name=name;
        this.price=price;
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public double getPrice(){
        return price;
    }
    public void setPrice(double price){
        this.price=price;
    }
}

A. <%= product.getName() %>
B. <jsp:useBean id="product" class="com.example.Product" />
<%= product.getName() %>
C. <jsp:useBean id="com.example.Product" scope="page">
<%= product.getName() %>
</jsp:useBean>
D. <jsp:useBean id="product" type="com.example.Product"
scope="page" />
<%= product.getName() %>
E. <jsp:useBean id="product" type="com.example.Product">
<%= product.getName() %>
</jsp:useBean>
Answer: B, D
解析:
jsp:useBean先引入Bean再在页面中使用。
scope默认为page(pageContext)
顺便讲下jsp:useBean的class和type的区别,class为bean的类(包括包名),type为bean的类型(父类或者接口)

Q: 166 If you want to use the Java EE platform's built-in type of authentication
that uses a custom HTML page for authentication, which two statements are true? (Choose two.)
A. Your deployment descriptor will need to contain this tag:
<auth-method>CUSTOM</auth-method>.
B. The related custom HTML login page must be named loginPage.html.
C. When you use this type of authentication, SSL is turned on automatically.
D. You must have a tag in your deployment descriptor that allows you to point to both a login HTML page and
an HTML page for handling any login errors.
E. In the HTML related to authentication for this application, you must use predefined variable names for the
variables that store the user and password values.
Answer: D, E
解析:
<auth-method>的取值为BASIC/FORM/DIGEST/CLIENT-CERT
D.必须指定登录页面和错误页面
E.登录页面的用户名和密码必须指定

Q: 167 Given the two security constraints in a deployment descriptor:
101. <security-constraint>
102. <!--a correct url-pattern and http-method goes here-->
103. <auth-constraint><role-name>SALES</role-name></auth-
103. <auth-constraint>
104. <role-name>SALES</role-name>
105. </auth-constraint>
106. </security-constraint>
107. <security-constraint>
108. <!--a correct url-pattern and http-method goes here-->
109. <!-- Insert an auth-constraint here -->
110. </security-constraint>
If the two security constraints have the same url-pattern and http-method, which two, inserted
independently at line 109, will allow users with role names of either SALES or MARKETING to access
this resource? (Choose two.)
A. <auth-constraint/>
B. <auth-constraint>
<role-name>*</role-name>
</auth-constraint>
C. <auth-constraint>
<role-name>ANY</role-name>
</auth-constraint>
D. <auth-constraint>
<role-name>MARKETING</role-name>
</auth-constraint>
Answer: B, D
解析:A.表示没有用户可以访问该资源。

Q: 168 Which two are valid values for the <transport-guarantee> element inside a
<security-constraint> element of a web application deployment descriptor? (Choose two.)
A.NULL
B.SECURE
C.INTEGRAL
D.ENCRYPTED
E.CONFIDENTIAL
Answer: C, E
解析:<transport-guarantee>的元素必须有如下值:
NONE:不需要传输保证
INTEGRAL:确保数据的真实性,数据传输过程中不嫩更改
CONFIDENTIAL:只有授权的用户能读取数据,即传输必须加密。

Q: 169 Which basic authentication type is optional for a J2EE 1.4 compliant web
container?
A.HTTP Basic Authentication
B.Form Based Authentication
C.HTTP Digest Authentication
D.HTTPS Client Authentication
Answer: C
解析:
C.HTTP Digest Authentication(摘要认证)

Q: 170 Which security mechanism uses the concept of a realm?
A.authorization
B.data integrity
C.confidentiality
D.authentication
Answer: D
解析:
A.authorization授权
D.authentication认证(使用域控制)

Q: 171 Which two security mechanisms can be directed through a sub-element of
the <user-data-constraint> element in a web application deployment descriptor? (Choose two.)
A.authorization
B.data integrity
C.confidentiality
D.authentication
Answer: B, C
解析:<user-data-constraint>用于设置怎么保护数据传输,
必须包含一个transport-guarantee子元素,可选值如下:
NONE:不用传输保证。
INTEGRAL:保密传输,途中不能改变。
CONFIDENTIAL:传送的数据必须是加密的。

Q: 172 You are developing several tag libraries that will be sold for development
of third-party web applications. You are about to publish the first three libraries as JAR files:
container-tags.jar, advanced-html-form-tags.jar, and basic-html-form-tags.jar. Which two techniques are
appropriate for packaging the TLD files for these tag libraries? (Choose two.)
A.The TLD must be located within the WEB-INF directory of the JAR file.
B.The TLD must be located within the META-INF directory of the JAR file.
C.The TLD must be located within the META-INF/tld/ directory of the JAR file.
D.The TLD must be located within a subdirectory of WEB-INF directory of the JAR file.
E.The TLD must be located within a subdirectory of META-INF directory of the JAR file.
F.The TLD must be located within a subdirectory of META-INF/tld/ directory of the JAR file.
Answer: B, E
解析:jar中的tld文件必须放在META-INF文件下或该文件子文件下,才能识别。

Q: 173 A custom tag is defined to take three attributes. Which two correctly
invoke the tag within a JSP page? (Choose two.)
A. <prefix:myTag a="foo" b="bar" c="baz" />
B. <prefix:myTag attributes={"foo","bar","baz"} />
C. <prefix:myTag jsp:attribute a="foo" b="bar" c="baz" />
D. <prefix:myTag>
   <jsp:attribute a:foo b:bar c:baz />
   </prefix:myTag>
E. <prefix:myTag>
   <jsp:attribute ${"foo", "bar", "baz"} />
   </prefix:myTag>
F. <prefix:myTag>
   <jsp:attribute a="foo" b="bar" c="baz"/>
   </prefix:myTag>
G. <prefix:myTag>
   <jsp:attribute name="a">foo</jsp:attribute>
   <jsp:attribute name="b">bar</jsp:attribute>
   <jsp:attribute name="c">baz</jsp:attribute>
   </prefix:myTag>
Answer: A, G
解析:自定义标签myTag能同时设置三个属性值
jsp:attribute用于设置属性。

Q: 174 In a JSP-centric shopping cart application, you need to move a client's
home address of the Customer object into the shipping address of the Order object. The address data is
stored in a value object class called Address with properties for: street address, city, province, country,
and postal code. Which two JSP code snippets can be used to accomplish this goal? (Choose two.)
A. <c:set var='order' property='shipAddress' value='${client.homeAddress}' />
B. <c:set target='${order}' property='shipAddress' value='${client.homeAddress}' />
C. <jsp:setProperty name='${order}' property='shipAddress' value='${client.homeAddress}' />
D. <c:set var='order' property='shipAddress'>
   <jsp:getProperty name='client' property='homeAddress' />
   </c:store>
E. <c:set target='${order}' property='shipAddress'>
   <jsp:getProperty name='client' property='homeAddress' />
   </c:set>
F. <c:setProperty name='${order}' property='shipAddress'>
   <jsp:getProperty name='client' property='homeAddress' />
   </c:setProperty>
Answer: B, E
解析:c:set标签有两种设置:var和target
var用于设置域属性,target版本用于设置bean属性或Map值
如果target指定是一个bean,property用于指定bean的一个属性,value指定属性值。

Q: 175 You have been contracted to create a web site for a free dating service.
One feature is the ability for one client to send a message to another client, which is displayed in the latter
client's private page. Your contract explicitly states that security is a high priority. Therefore, you need to
prevent cross-site hacking in which one user inserts JavaScript code that is then rendered and invoked
when another user views that content. Which two JSTL code snippets will prevent cross-site hacking in
the scenario above? (Choose two.)
A.<c:out>${message}</c:out>
B.<c:out value='${message}' />
C.<c:out value='${message}' escapeXml='true' />
D.<c:out eliminateXml='true'>${message}</c:out>
E.<c:out value='${message}' eliminateXml='true' />
Answer: B, C
解析:c:out用于显示表达式的值,有如下属性:
value:定义求解的表达式。
escapeXML:可选属性,指定输出特殊标记,如果为true,则自动处理。

Q: 176 Click the Exhibit button.
Assuming the tag library in the exhibit is imported with the prefix forum, which custom tag invocation
produces a translation error in a JSP page?
<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd" version="2.0">
    <tlib-version>1.0</tlib-version>
    <short-name>forum</short-name>
    <uri>http://example.com/tld/forum</uri>
    <tag>
        <name>message</name>
        <tag-class>com.example.MessageTag</tag-class>
        <body-content>scriptless</body-content>
        <attribute>
            <name>from</name>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <attribute>
            <name>subject</name>
            <required>false</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
</taglib>

A. <forum:message from="My Name" subject="My Subject" />
B. <forum:message subject="My Subject">
   My message body.
   </forum:message>
C. <forum:message from="My Name" subject="${param.subject}">
   ${param.body}
   </forum:message>
D. <forum:message from="My Name" subject="My Subject">
   <%= request.getParameter( "body" ) %>
   </forum:message>
E. <forum:message from="My Name" subject="<%= request.getParameter( "subject" ) %>">
   My message body.
   </forum:message>
Answer: D
解析:

题目要求选择产生编译错误的选项。
<body-content>设置可以使用scriptless但是不能使用scriptlet,所以D不正确
<rtexprvalue>设置属性取动态值还是静态值,如果true可以取动态值例如EL表达式



Q: 177 Which JSTL code snippet can be used to import content from another web
resource?
A.<c:import url="foo.jsp"/>
B.<c:import page="foo.jsp"/>
C.<c:include url="foo.jsp"/>
D.<c:include page="foo.jsp"/>
E.Importing cannot be done in JSTL. A standard action must be used instead.
Answer: A
解析:<c:import url="">相当于<jsp:include page="">

Q: 178 Click the Exhibit button.
Assume the tag library in the exhibit is placed in a web application in the path
/WEB-INF/tld/example.tld.
1.
2. <ex:hello />
Which JSP code, inserted at line 1, completes the JSP code to invoke the hello tag?
<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd" version="2.0">
    <tlib-version>1.0</tlib-version>
    <short-name>ex</short-name>
    <uri>http://example.com/tld/example</uri>
    <tag>
        <name>hello</name>
        <tag-class>com.example.HelloTag</tag-class>
        <body-content>scriptless</body-content>
    </tag>
</taglib>

A. <%@ taglib prefix="ex" uri="/WEB-INF/tld" %>
B. <%@ taglib uri="/WEB-INF/tld/example.tld" %>
C. <%@ taglib prefix="ex" uri="http://localhost:8080/tld/example.tld" %>
D. <%@ taglib prefix="ex" uri="http://example.com/tld/example" %>
Answer: D
解析:taglib的设置要按照tag library中的属性,short-name即前缀,uri为路径。

Q: 179 Which JSTL code snippet produces the output "big number" when X is
greater than 42, but outputs "small number" in all other cases?
A. <c:if test='<%= (X > 42) %>'>
   <c:then>big number</c:then>
   <c:else>small number</c:else>
   </c:if>
B. <c:if>
   <c:then test='<%= (X > 42) %>'>big number</c:then>
   <c:else>small number</c:else>
   </c:if>
C. <c:choose test='<%= (X > 42) %>'>
   <c:then>big number</c:when>
   <c:else>small number</c:otherwise>
   </c:choose>
D. <c:choose test='<%= (X > 42) %>'>
   <c:when>big number</c:when>
   <c:otherwise>small number</c:otherwise>
   </c:choose>
E. <c:choose>
   <c:when test='<%= (X > 42) %>'>big number</c:when>
   <c:otherwise>small number</c:otherwise>
   </c:choose>
Answer: E
解析:jstl中没有else(then也没有)的用法,可以如下替代:
<c:choose>
    <c:when test="">if</c:when>
    <c:otherwise>else</otherwise>
<c:choose>

Q: 180 A developer chooses to avoid using SingleThreadModel but wants to
ensure that data is updated in a thread-safe manner. Which two can support this design goal? (Choose
two.)
A.Store the data in a local variable.
B.Store the data in an instance variable.
C.Store the data in the HttpSession object.
D.Store the data in the ServletContext object.
E.Store the data in the ServletRequest object.
Answer: A, E
解析:本地变量和ServletRequest对象是线程安全的。

Q: 181 Your web application uses a simple architecture in which servlets handle
requests and then forward to a JSP using a request dispatcher. You need to pass information calculated
in the servlet to the JSP for view generation. This information must NOT be accessible to any other
servlet, JSP or session in the webapp. Which two techniques can you use to accomplish this goal?
(Choose two.)
A.Add attributes to the session object.
B.Add attributes on the request object.
C.Add parameters to the request object.
D.Use the pageContext object to add request attributes.
E.Add parameters to the JSP's URL when generating the request dispatcher.
Answer: B, E
解析:(同134)要不被其它servlet访问,可以将其属性添加到request域中,或在路径后添加属性和值。

Q: 182 For which three events can web application event listeners be registered?
(Choose three.)
A.when a session is created
B.after a servlet is destroyed
C.when a session has timed out
D.when a cookie has been created
E.when a servlet has forwarded a request
F.when a session attribute value is changed
Answer: A, C, F
解析:
A.session created->sessionCreated(HttpSessonListener)
C.session timeout->SessionDestroyed(HttpSessionListener)
F.session changed->Attribute Added/Removed/Replaced(HttpSessionAttributeEvent)

Q: 183 Given:
String value = getServletContext().getInitParameter("foo");
in an HttpServlet and a web application deployment descriptor that contains:
<context-param>
<param-name>foo</param-name>
<param-value>frodo</param-value>
</context-param>
Which two are true? (Choose two.)
A.The foo initialization parameter CANNOT be set programmatically.
B.Compilation fails because getInitParameter returns type Object.
C.The foo initialization parameter is NOT a servlet initialization parameter.
D.Compilation fails because ServletContext does NOT have a getInitParameter method.
E.The foo parameter must be defined within the <servlet> element of the deployment descriptor.
F.The foo initialization parameter can also be retrieved using getServletConfig().getInitParameter("foo").
Answer: A, C
解析:
A.foo的值只能读取,不能设置。
C.foo是application(servletcontext)范围的参数,
  servlet范围参数用<init-param>设置。

Q: 184 Click the Exhibit button. Given the web application deployment descriptor
elements:
11. <filter>
12. <filter-name>ParamAdder</filter-name>
13. <filter-class>com.example.ParamAdder</filter-class>
14. </filter>
...
31.<filter-mapping>
32.<filter-name>ParamAdder</filter-name>
33.<servlet-name>Destination</servlet-name>
34.</filter-mapping>
...
55.<servlet-mapping>
56.<servlet-name>Destination</servlet-name>
57.<url-pattern>/dest/Destination</url-pattern>
58.</servlet-mapping>
What is the result of a client request of the Source servlet with no query string?
//Source Servlet:Source.java
public class Source extends HttpServlet{
    public void service(HttpServletRequest request,HttpServletResponse response)
        throws ServletException,IOException{
            RequestDispatcher rd=request.getRequestDispatcher("/dest/Destination");
            rd.forward(request,response);
        }
}

//Filter:ParamAdder.java
public class ParamAdder implements Filter{
    //...
    public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)
        throws ServletException,IOException{
            request.setAttribute("filterAdded","addedByFilter");
            chain.doFilter(request,response);
        }
        //...
}

//Destination Servlet Destination.java
public class Destination extends HttpServlet{
    public void service(HttpServletRequest request,HttpServletResponse response)
        throws ServletException,IOException{
            String filterParam=(String)request.getAttribute("filterAdded");
            response.getWriter().println("filterAdded="+filterParam);
        }
}
A.The output "filterAdded = null" is written to the response stream.
B.The output "filterAdded = addedByFilter" is written to the response stream.
C.An exception is thrown at runtime within the service method of the Source servlet.
D.An exception is thrown at runtime within the service method of the Destination servlet.
Answer: A

解析:servlet-2.4Filter默认下只拦截外部提交,forwardinclude这些内部转发不会被拦截,

如果要求处理内部拦截必须配置<dispatcher>FORWARD</dispatcher>

所以题中的filter没有执行。



Q: 185 Given a Filter class definition with this method:
21. public void doFilter(ServletRequest request,
22. ServletResponse response,
23. FilterChain chain)
24. throws ServletException, IOException {
25. // insert code here
26. }
Which should you insert at line 25 to properly invoke the next filter in the chain, or the target servlet if
there are no more filters?
A.chain.forward(request, response);
B.chain.doFilter(request, response);
C.request.forward(request, response);
D.request.doFilter(request, response);
Answer: B
解析:FilterChain.doFilter(request,response)跳转到下一个过滤器或页面;

Q: 186 Servlet A forwarded a request to servlet B using the forward method of
RequestDispatcher. What attribute in B's request object contains the URI of the original request received
by servlet A?
A.REQUEST_URI
B.javax.servlet.forward.request_uri
C.javax.servlet.forward.REQUEST_URI
D.javax.servlet.request_dispatcher.request_uri
E.javax.servlet.request_dispatcher.REQUEST_URI
Answer: B
解析:javax.servlet.forward.request_uri跳转前的原始路径。

Q: 187 You want to create a valid directory structure for your Java EE web
application, and you want to put your web application into a WAR file called MyApp.war. Which two
are true about the WAR file? (Choose two.)
A. At deploy time, Java EE containers add a directory called META-INF directly into the MyApp directory.
B. At deploy time, Java EE containers add a file called MANIFEST.MF directly into the MyApp directory.
C. It can instruct your Java EE container to verify, at deploy time, whether you have properly configured your
application's classes.
D. At deploy time, Java EE containers add a directory call META-WAR directly into the MyApp directory.
Answer: A, C
解析:
A.部署时,容器会加载META-INF中的配置文件。
C.容器加载配置文件,检查配置是否正确

Q: 188 Which two from the web application deployment descriptor are valid?
(Choose two.)
A. <error-page>
   <exception-type>*</exception-type>
   <location>/error.html</location>
   </error-page>
B. <error-page>
   <exception-type>java.lang.Error</exception-type>
   <location>/error.html</location>
   </error-page>
C. <error-page>
   <exception-type>java.lang.Throwable</exception-type>
   <location>/error.html</location>
   </error-page>
D. <error-page>
   <exception-type>java.io.IOException</exception-type>
   <location>/error.html</location>
   </error-page>
E. <error-page>
   <exception-type>NullPointerException</exception-type>
   <location>/error.html</location>
   </error-page>
Answer: C, D
解析:
在web.xml中设置错误页面的方法有两种:
错误码(<error-code>)或异常类型(<exception-type)
java.lang.Error不是异常

Q: 189 After a merger with another small business, your company has inherited a
legacy WAR file but the original source files were lost. After reading the documentation of that web
application, you discover that the WAR file contains a useful tag library that you want to reuse in your
own webapp packaged as a WAR file.
What do you need to do to reuse this tag library?
A. Simply rename the legacy WAR file as a JAR file and place it in your webapp's library directory.
B. Unpack the legacy WAR file, move the TLD file to the META-INF directory, repackage the whole thing as
a JAR file, and place that JAR file in your webapp's library directory.
C. Unpack the legacy WAR file, move the TLD file to the META-INF directory, move the class files to the
top-level directory, repackage the whole thing as a JAR file, and place that JAR file in your webapp's library
directory.
D. Unpack the legacy WAR file, move the TLD file to the META-INF directory, move the class files to the
top-level directory, repackage the WAR, and place that WAR file in your webapp's WEB-INF directory.
Answer: C
解析:(同44题)解压war文件,把tld文件和class文件放置在自己的程序下,达到复用的目的,再把自己的程序打包成war使用。

Q: 190 Which path is required to be present within a WAR file?
A./classes
B./index.html
C./MANIFEST-INF
D./WEB-INF/web.xml
E./WEB-INF/classes
F./WEB-INF/index.html
G./META-INF/index.xml
Answer: D
解析:
D.web.xml程序配置文件

Q: 191 Given:
11. <servlet>
12. <servlet-name>catalog</servlet-name>
13. <jsp-file>/catalogTemplate.jsp</jsp-file>
14. <load-on-startup>10</load-on-startup>
15. </servlet>
Which two are true? (Choose two.)
A.Line 13 is not valid for a servlet declaration.
B.Line 14 is not valid for a servlet declaration.
C.One instance of the servlet will be loaded at startup.
D.Ten instances of the servlet will be loaded at startup.
E.The servlet will be referenced by the name catalog in mappings.
Answer: C, E
解析:
<load-on-startup>设置容器是否在启动是加载该servlet
当值为0或者大于0时,表示启动时加载.
C.启动是会加载一个servlet实例
E.mapping的名字应该是该servlet的名字

Q: 192 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
解析:(同76题)设置xml错误页面
<error-page>
<error-code>..</error-code>(或者<exception-type>)
<location>..</location>
</error-page>

Q: 193 Given a portion of a valid Java EE web application's directory structure:
MyApp
|
|-- Directory1
| |-- File1.html
|
|-- META-INF
| |-- File2.html
|
|-- WEB-INF
|   |-- File3.html
You want to know whether File1.html, File2.html, and/or File3.html is protected from direct access by
your web client's browsers.
What statement is true?
A.All three files are directly accessible.
B.Only File1.html is directly accessible.
C.Only File2.html is directly accessible.
D.Only File3.html is directly accessible.
E.Only File1.html and File2.html are directly accessible.
F.Only File1.html and File3.html are directly accessible.
G.Only File2.html and File3.html are directly accessible.
Answer: B
解析:META-INF和WEB-INF目录默认禁止访问。

Q: 194 A web component accesses a local EJB session bean with a component
interface of com.example.Account with a home interface of com.example.AccountHome and a JNDI
reference of ejb/Account. Which makes the local EJB component accessible to the web components in the
web application deployment descriptor?
A. <env-ref>
   <ejb-ref-name>ejb/Account</ejb-ref-name>
   <ejb-ref-type>Session</ejb-ref-type>
   <local-home>com.example.AccountHome</local-home>
   <local>com.example.Account</local>
   </env-ref>
B. <resource-ref>
   <ejb-ref-name>ejb/Account</ejb-ref-name>
   <ejb-ref-type>Session</ejb-ref-type>
   <local-home>com.example.AccountHome</local-home>
   <local>com.example.Account</local>
   </resource-ref>
C. <ejb-local-ref>
   <ejb-ref-name>ejb/Account</ejb-ref-name>
   <ejb-ref-type>Session</ejb-ref-type>
   <local-home>com.example.AccountHome</local-home>
   <local>com.example.Account</local>
   </ejb-local-ref>
D. <ejb-remote-ref>
   <ejb-ref-name>ejb/Account</ejb-ref-name>
   <ejb-ref-type>Session</ejb-ref-type>
   <local-home>com.example.AccountHome</local-home>
   <local>com.example.Account</local>
   </ejb-remote-ref>
Answer: C
解析:
<resource-ref>资源引用
<resource-env-ref>资源环境引用
<ejb-ref>声明对bean的home接口的引用。
<ejb-local-ref>声明对bean的本地home接口的引用。

Q: 195 One of the use cases in your web application uses many session-scoped
attributes. At the end of the use case, you want to clear out this set of attributes from the session object.
Assume that this static variable holds this set of attribute names:
201. private static final Set<String> USE_CASE_ATTRS;
202. static {
203. USE_CASE_ATTRS.add("customerOID");
204. USE_CASE_ATTRS.add("custMgrBean");
205. USE_CASE_ATTRS.add("orderOID");
206. USE_CASE_ATTRS.add("orderMgrBean");
207. }
Which code snippet deletes these attributes from the session object?
A. session.removeAll(USE_CASE_ATTRS);
B. for ( String attr : USE_CASE_ATTRS ) {
    session.remove(attr);
}
C. for ( String attr : USE_CASE_ATTRS ) {
    session.removeAttribute(attr);
}
D. for ( String attr : USE_CASE_ATTRS ) {
    session.deleteAttribute(attr);
}
E. session.deleteAllAttributes(USE_CASE_ATTRS);
Answer: C
解析:HttpSession删除属性方法removeAttribute();

Q: 196 Given an HttpServletRequest request:
22. String id = request.getParameter("jsessionid");
23. // insert code here
24. String name = (String) session.getAttribute("name");
Which three can be placed at line 23 to retrieve an existing HttpSession object? (Choose three.)
A.HttpSession session = request.getSession();
B.HttpSession session = request.getSession(id);
C.HttpSession session = request.getSession(true);
D.HttpSession session = request.getSession(false);
E.HttpSession session = request.getSession("jsessionid");
Answer: A, C, D
解析:HttpServletRequest获取HttpSession的方法有:
getSession(),getSession(boolean create)a

Q: 197 A developer for the company web site has been told that users may turn off
cookie support in their browsers. What must the developer do to ensure that these customers can still use
the web application?
A. The developer must ensure that every URL is properly encoded using the appropriate URL rewriting APIs.
B. The developer must provide an alternate mechanism for managing sessions and abandon the HttpSession
mechanism entirely.
C. The developer can ignore this issue. Web containers are required to support automatic URL rewriting when
cookies are not supported.
D. The developer must add the string ?id=<sessionid> to the end of every URL to ensure that the conversation
with the browser can continue.
Answer: A
解析:(同22题)禁用cookie后,能使用URL重写传送参数

Q: 198 You need to store a floating point number, called Tsquare, in the session
scope. Which two code snippets allow you to retrieve this value? (Choose two.)
A.float Tsquare = session.getFloatAttribute("Tsquare");
B.float Tsquare = (Float) session.getAttribute("Tsquare");
C.float Tsquare = (float) session.getNumericAttribute("Tsquare");
D.float Tsquare = ((Float) session.getAttribute.("Tsquare")).floatValue();
E.float Tsquare = ((Float) session.getFloatAttribute.("Tsquare")).floatValue;
F.float Tsquare = ((Float) session.getNumericAttribute.("Tsquare")).floatValue;
Answer: B, D
解析:session.getAttribute获取session中的参数。

Q: 199 Given the definition of MyObject and that an instance of MyObject is
bound as a session attribute:
8. package com.example;
9. public class MyObject implements
10.javax.servlet.http.HttpSessionBindingListener {
11. // class body code here
12. }
Which is true?
A. Only a single instance of MyObject may exist within a session.
B. The unbound method of the MyObject instance is called when the session to which it is bound times out.
C. The com.example.MyObject must be declared as a servlet event listener in the web application deployment
descriptor.
D. The valueUnbound method of the MyObject instance is called when the session to which it is bound times
out.
Answer: D
解析:HttpSessionBindingListener有两个方法:valueBound()和valueUnbound()

Q: 200 As a convenience feature, your web pages include an Ajax request every
five minutes to a special servlet that monitors the age of the user's session. The client-side JavaScript that
handles the Ajax callback displays a message on the screen as the session ages. The Ajax call does NOT
pass any cookies, but it passes the session ID in a request parameter called sessionID. In addition, assume
that your webapp keeps a hashmap of session objects by the ID. Here is a partial implementation of this
servlet:
10. public class SessionAgeServlet extends HttpServlet {
11. public void service(HttpServletRequest request, HttpServletResponse) throws IOException {
12. String sessionID = request.getParameter("sessionID");
13. HttpSession session = getSession(sessionID);
14. long age = // your code here
15. response.getWriter().print(age);
16. }
... // more code here
47. }
Which code snippet on line 14, will determine the age of the session?
A.session.getMaxInactiveInterval();
B.session.getLastAccessed().getTime() - session.getCreationTime().getTime();
C.session.getLastAccessedTime().getTime() - session.getCreationTime().getTime();
D.session.getLastAccessed() - session.getCreationTime();
E.session.getMaxInactiveInterval() - session.getCreationTime();
F.session.getLastAccessedTime() - session.getCreationTime();
Answer: F
解析:(同24题)最后访问时间-创建时间(不用再getTime)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值