JSP Actions Quiz

Answer the following questions and click 'Mark Test' when finished to see how well you did.

  1. Which of the following can the JSP include action include output from ?
    Another JSP
    Plain text file
    CGI Program
    Servlet
    All of the above

     

  2. The <jsp:include/> action can pass parameters to the page which it is including. How does this second page obtain the value of these parameters ?
    Using the <jsp:readParam/> action
    Using the <jsp:getParam/> action
    Use the request.getParameter() method
    Use the response.getParameter() method

     

  3. What is wrong with the following code ?
    <%
    if(strPassword.equals("boss"))
    {
      <jsp:forward page="Welcome.jsp" flush="true"/>
    }
    else
    {
      <jsp:forward page="Login.jsp" flush="true"/>
    }
    %>
    
    Unmatched bracket in for statement
    Flush attribute must be false
    Keyword 'file' should be used instead of 'page' in the <jsp:forward/> action
    Actions cannot be used within scriptlet blocks

     

  4. What is wrong with the following code ?
    <jsp:include page="MainMenu.jsp" flush="true"/>
    <%
    Cookie c = new Cookie("UserName", "Alastair Gulland");
    response.addCookie(c);
    %>
    
    Cookie class can not take parameters in it's constructor
    The request object is used for creating cookies
    Although no error will be reported the use of the <jsp:include/> action means that the response object can't be used to create cookies.
    The <jsp:include/> action must be placed inside the script block

     

 JavaBeans

The next topic covers JavaBenas. JavaBeans are another Java technology that can be used by a JSP in a very effective way.

Back Next