Servlets and JSP

Pēdējais mainījis Administrator 2011-06-06 17:30

This test covers basic things that are defined in Servlet 2.4 (and JSP 2.0) specifications and used by Java Web applications

Jauns jautājums:

Prasmes

  1. Tag Libraries Understand how to declare and use tag libraries.
  2. Servlet Lifecycle Understand servlet creation, initialization and destruction
  3. Issues of Servlet Programming Serving requests, receiving HTTP parameters, handling responses, logging, etc.
  4. Issues of JSP Programming Directives, expressions, scriptlets; "jsp:useBean" and related constructs.
  5. Session State, Scopes Various scopes, sessions and HTTP mechanisms related to HttpSession, synchronization issues.
  6. Servlet Deployment Understand how servlet container interacts with servlets and JSPs depending on the descriptor web.xml

1. Tag Libraries

  • 1001
    Read the following code snippet.
    <taglib>
        <taglib-uri>
                http://www.yourcompany.com/yourTagLibrary
        </taglib-uri>
        <taglib-location>
           /WEB-INF/yourTagLibrary.tld
        </taglib-location>
    </taglib>
    What statement applies to this code snippet?
    1. The tablib element of the deployment descriptor is required if you use a taglib directive in a JSP page that references a TLD by name (indirectly) rather than by location (directly).
    2. This tag goes into the WEB-INF/myApplication/web.xml file.
    3. This definition is incorrect because the taglib-uri should have been uri.
    4. This definition is incorrect because the taglib should have been tag.

2. Servlet Lifecycle

  • 2001
    How would you retrieve servlet-initialization parameters? (By "paramName" we denote the name of a parameter; by "paramIndex" - its number in the order of declarations).
    1. String value = getServletConfig().getInitParameter("paramName");
    2. String value = getServletConfig().getInitParameter(paramIndex);
    3. String value = getServletConfig().getParameter("paramName");
    4. String value = getServletConfig().getParameter(paramIndex);
  • 2002
    How do you declare initialization parameters for the servlet in the deployment descriptor?
    1. <web-app>
        <servlet>
          <servletname>servletName</servletname>
          <servletclass>com.myCo.MyServlet</servletclass>
          <initparam>
            <paramname>color</paramname>
            <paramvalue>blue</paramvalue>
          </initparam>
        </servlet>
      </web-app>
    2. <web-app>
        <servlet>
          <servlet-name>servletName</servlet-name>
          <servlet-class>com.myCo.MyServlet</servlet-class>
          <init-param>
            <name>color</name>
            <value>blue</value>
          </init-param>
        </servlet>
      </web-app>
    3. <web-app>
        <servlet>
          <name>servletName</name>
          <class>com.myCo.MyServlet</class>
          <init-param>
            <param-name>color</param-name>
            <param-value>blue</param-value>
          </init-param>
        </servlet>
      </web-app>
    4. <web-app>
        <servlet>
          <servlet-name>servletName</servlet-name>
          <servlet-class>com.myCo.MyServlet</servlet-class>
          <init-param>
            <param-name>color</param-name>
            <param-value>blue</param-value>
          </init-param>
        </servlet>
      </web-app>
  • 2003
    What method is called by the servlet container just before this servlet is put into service?
    1. public void init() throws IOException { //code }
    2. public void start() throws IOException { //code }
    3. public void service() throws ServletException { //code }
    4. public void init() throws ServletException { //code }
  • 2004
    What method is called by the servlet container just after the servlet is removed from service?
    1. public void destroy() { // code… }
    2. public void destroy() throws ServletException { // code… }
    3. public void finalize() throws ServletException { // code… }
    4. public void finalize() { // code… }

3. Issues of Servlet Programming

  • 3002
    How would you add an entry to the log file from a servlet assuming that e is an initialized Exception object?
    1. getServletConfig().log("An exception occurred", e);
    2. getServletConfig().logger(e);
    3. getServletContext().log(e);
    4. getServletContext().log("An exception occurred", e);
  • 3003
    Assuming that the servlet method for handling HTTP GET requests is doGet(HttpServletRequest request, HttpServletResponse response), how do you get a request parameter in that servlet?
    1. String value = request.getInitParameter("name");
    2. String value = response.getParameter("name");
    3. String value = request.getParameter("name");
    4. String value = request.getInitParameter(10);
  • 3004
    Assuming that the servlet method for handling HTTP GET requests is doGet(HttpServletRequest request, HttpServletResponse response), which two statements are true regarding the following code snippet?
    Enumeration enum = request.getParameterNames();

    Izvēlēties 2 no N
    1. This is how you retrieve the names of all request parameters.
    2. This is how you would then get the name of the next request parameter:
      name = (String)enum.nextElement();
    3. The code snippet in the question will not work. The return type is a String array, not an Enumeration object.
    4. This would have worked had the code been:
      String[] names = request.getParameterNames();
  • 3005
    Which one of the following is the most likely trigger to cause a browser to use the HTTP HEAD method?
    1. Client sends updated information to server.
    2. Server sends HTTP HEAD to client.
    3. Server requests HTTP HEAD of client.
    4. Client checks resource modification date/time.
  • 3006
    What interface and method name should be used to acquire a binary stream for the response?
    1. ServletResponse.getOutputStream
    2. ServletResponse.getStream
    3. ServletResponse.getWriterStream
    4. ServletResponse.getWriter

4. Issues of JSP Programming

  • 4001
    How do you perform a server-side include whose content gets translated within the JSP page?
    1. include action
    2. include directive
    3. include scriptlet
    4. include expression
  • 4002
    How would you include dynamic content in a JSP page that doesn't get translated within the context of the current page?

    1. <%@ page import="footer.html" %>
    2. include directive
    3. <%@include file="footer.html" %>
    4. jsp:include
  • 4003
    Which two of the following are valid attributes of the JSP page directive?
    Izvēlēties 2 no N
    1. extends="package.class"
    2. errorPage="true"
    3. buffer="false"
    4. import="package.class"
  • 4004
    What is an example of an expression?
    1. <%= count %>
    2. <% String count=4; %>
    3. <% out.print("hello"); %>
    4. <%! String count=4; %>
  • 4005
    Which one of the following is not an attribute of the jsp:useBean tag?
    1. scope
    2. name
    3. type
    4. class
  • 4006
    Which two of the following pairs are equivalents?
    Izvēlēties 2 no N
    1. <% yourCode %>
      and
      <jsp:scriptlet>yourCode</jsp:scriptlet>
    2. ServletContext.useBean("beanName",id,scope, class);
      and
      <jsp:useBean id="customer" 
        scope="page" class="session.Customer" />
    3. <%@ taglib uri="URIForLibrary" prefix="tagPrefix" %>
      and
      <jsp:taglib uri="URIForLibrary" prefix="tagPrefix" />
    4. <%@ page att="val" %>
      and
      <jsp:directive.page att="val"/>
  • 4007
    How can you set several attributes of a Bean at the same time?
    1. You can't. They must be done individually.
    2. You do this with the deployment descriptor.
    3. You use the jsp:setProperty action with the property attribute set to the wildcard *.
    4. You use the jsp:useBean and list the attributes in this tag together.
  • 4008
    Read the following listing.
    1.  <html>
    2.    <body>
    3.
    4.      <% x = x - 15; %>
    5.      New customers: <%= x %>
    6.    </body>
    7.  </html>
    What should be inserted on line 3 to allow successful compilation and produce an output of New customers: 20?
    1. <%! int x = 35 %>
    2. <%@ int x = 35; %>
    3. <% int x = 35 ; %>
    4. int x = 35;
  • 4009
    Read the following code snippet.
    <%= myBean.getColor() %>
    What option will produce the same result?
    1. <jsp:getProperty name=myBean property=color />
    2. <jsp:getProperty "myBean.getColor" />
    3. <jsp:getProperty bean1.getColor/>
    4. <jsp:getProperty name="myBean" property="color" />

5. Session State, Scopes

  • 5001
    Which two of the following methods are used to access object attributes within the session scope?
    Izvēlēties 2 no N
    1. getNames
    2. getSessionAttributes
    3. getAttribute
    4. getAttributeNames
  • 5002
    What is the interface used to access values and resources and to set object attributes within the session scope?
    1. HttpSession
    2. RequestSession
    3. HttpRequestSession
    4. Session
  • 5003
    What method accesses attributes within the request scope?
    1. getAttributes
    2. getNames
    3. getAttributeNames
    4. getNamedAttribute
  • 5004
    How could you reference a session in a servlet?
    1. Session mySession = Context.getSession();
    2. Session mySession = pageContext.getHttpSession();
    3. HttpSession mySession = pageContext.getHttpSession();
    4. HttpSession mySession = pageContext.getSession();
  • 5005
    Which two of the following methods are used to access resources within the context scope?
    Izvēlēties 2 no N
    1. getSession
    2. getNamedDispatcher
    3. getDispatcher
    4. getRequestDispatcher
  • 5006
    Which two of the following methods are used to access values and resources and to set object attributes within the session scope?
    Izvēlēties 2 no N
    1. setAttribute
    2. removeAttributeName
    3. deleteAttribute
    4. removeAttribute

6. Servlet Deployment

  • 6001
    Which two of the following statements are true regarding declaring a servlet instance in a deployment descriptor?
    Izvēlēties 2 no N
    1. The servlet element specifies the fully qualified class name of the servlet.
    2. The tags are nested within <web-app> </web-app> tags.
    3. The tags do not define parameters.
    4. The tags are <servlet-instance></servlet-instance>.
  • 6002
    How many servlet mappings in a deployment descriptor may be defined for one Web app?
    1. Unlimited.
    2. Servlet mappings don't go into the deployment descriptor.
    3. Zero.
    4. One.

Citi jautājumi

Tagi:
Izveidojis Kalvis Apsītis 2007-12-31 21:17
    
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 6.4 - Documentation