QUESTION NO: 131
You want to create a filter for your web application and your filter will implement
javax.servlet.Filter.
Which two statements are true? (Choose two.)
A. Your filter class must implement an init method and a destroy method.
B. Your filter class must also implement javax.servlet.FilterChain.
C. When your filter chains to the next filter, it should pass the same arguments it received in its
doFilter method.
D. The method that your filter invokes on the object it received that implements
javax.servlet.FilterChain can invoke either another filter or a servlet.
E. Your filter class must implement a doFilter method that takes, among other things, an
HTTPServletRequest object and an HTTPServletResponse object.
Answer: A,D
QUESTION NO: 132
Your web site has many user-customizable features, for example font and color preferences on
web pages. Your IT department has already built a subsystem for user preferences using Java
SE's lang.util.prefs package APIs and you have been ordered to reuse this subsystem in your web
application. You need to create an event listener that stores the user's Preference object when an
HTTP session is created. Also, note that user identification information is stored in an HTTP
cookie.
Which partial listener class can accomplish this goal?
A. public class UserPrefLoader implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent se) {
MyPrefsFactory myFactory = (MyPrefsFactory)
se.getServletContext().getAttribute("myPrefsFactory");
User user = getUserFromCookie(se);
myFactory.setThreadLocalUser(user);
Preferences userPrefs = myFactory.userRoot();
se.getSession().setAttribute("prefs", userPrefs);
}
// more code here
}
B. public class UserPrefLoader implements SessionListener {
public void sessionCreated(SessionEvent se) {
MyPrefsFactory myFactory = (MyPrefsFactory) se.getContext().getAttribute("myPrefsFactory");
User user = getUserFromCookie(se);
myFactory.setThreadLocalUser(user);
Preferences userPrefs = myFactory.userRoot();
se.getSession().addAttribute("prefs", userPrefs);
}
// more code here
}
C. public class UserPrefLoader implements HttpSessionListener {
public void sessionInitialized(HttpSessionEvent se) {
MyPrefsFactory myFactory = (MyPrefsFactory)
se.getServletContext().getAttribute("myPrefsFactory");
User user = getUserFromCookie(se);
myFactory.setThreadLocalUser(user);
Preferences userPrefs = myFactory.userRoot();
se.getHttpSession().setAttribute("prefs", userPrefs);
}
// more code here
}
D. public class UserPrefLoader implements SessionListener {
public void sessionInitialized(SessionEvent se) {
MyPrefsFactory myFactory = (MyPrefsFactory)
se.getServletContext().getAttribute("myPrefsFactory");
User user = getUserFromCookie(se);
myFactory.setThreadLocalUser(user);
Preferences userPrefs = myFactory.userRoot();
se.getSession().addAttribute("prefs", userPrefs);
}
// more code here
}
Answer: A
QUESTION NO: 133
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>
...
24. <filter-mapping>
25. <filter-name>ParamAdder</filter-name>
26. <servlet-name>MyServlet</servlet-name>
27. <!-- insert element here -->
28. </filter-mapping>
Which element, inserted at line 27, causes the ParamAdder filter to be applied when MyServlet is
invoked by another servlet using the RequestDispatcher.include method?
A. <include/>
B. <dispatcher>INCLUDE</dispatcher>
C. <dispatcher>include</dispatcher>
D. <filter-condition>INCLUDE</filter-condition>
E. <filter-condition>include</filter-condition>
Answer: B
QUESTION NO: 134
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 by the
servlet to the JSP; furthermore, that JSP uses a custom tag and must also process this
information. This information must NOT be accessible to any other servlet, JSP or session in the
webapp. How can you accomplish this goal?
A. Store the data in a public instance variable in the servlet.
B. Add an attribute to the request object before using the request dispatcher.
C. Add an attribute to the context object before using the request dispatcher.
D. This CANNOT be done as the tag handler has no means to extract this data.
Answer: B
QUESTION NO: 135
A JSP page needs to set the property of a given JavaBean to a value that is calculated with the
JSP page. Which three jsp:setProperty attributes must be used to perform this initialization?
(Choose three.)
A. id
B. val
C. name
D. param
E. value
F. property
G. attribute
Answer: C,E,F
QUESTION NO: 136
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
QUESTION NO: 137
A JSP page needs to instantiate a JavaBean to be used by only that page. Which two jsp:useBean
attributes must be used to access this attribute in the JSP page? (Choose two.)
A. id
B. type
C. name
D. class
E. scope
F. create
Answer: A,D
QUESTION NO: 138
Click the Exhibit button.
Given the HTML form:
1. <html>
2. <body>
3. <form action="submit.jsp">
4. Name: <input type="text" name="i1"><br>
5. Price: <input type="text" name="i2"><br>
6. <input type="submit">
7. </form>
8. </body>
9. </html>
Assume the product attribute does NOT yet exist in any scope.
Which code snippet, in submit.jsp, instantiates an instance of com.example.Product that contains
the results of the form submission?
A. <jsp:useBean id="com.example.Product" />
<jsp:setProperty name="product" property="*" />
B. <jsp:useBean id="product" class="com.example.Product" />
${product.name = param.i1}
${product.price = param.i2}
C. <jsp:useBean id="product" class="com.example.Product">
<jsp:setProperty name="product" property="name"
param="i1" />
<jsp:setProperty name="product" property="price"
param="i2" />
</jsp:useBean>
D. <jsp:useBean id="product" type="com.example.Product">
<jsp:setProperty name="product" property="name"
value="<%= request.getParameter( "i1" ) %>" />
<jsp:setProperty name="product" property="price"
value="<%= request.getParameter( "i2" ) %>" />
</jsp:useBean>
Answer: C
QUESTION NO: 139 DRAG DROP
Click the Task button.
Place the events in the order they occur.
Answer:
QUESTION NO: 140
For an HttpServletResponse response, which two create a custom header? (Choose two.)
A. response.setHeader("X-MyHeader", "34");
B. response.addHeader("X-MyHeader", "34");
C. response.setHeader(new HttpHeader("X-MyHeader", "34"));
D. response.addHeader(new HttpHeader("X-MyHeader", "34"));
E. response.addHeader(new ServletHeader("X-MyHeader", "34"));
F. response.setHeader(new ServletHeader("X-MyHeader", "34"));
Answer: A,B
No comments:
Post a Comment