Your Ad Here

1. Which of the following is legal JSP syntax to print the value of i. Select the one correct answer
A. <%int i = 1;%>
<%= i; %>
B. <%int i = 1;
i; %>
C. <%int i = 1%>
<%= i %>
D. <%int i = 1;%>
<%= i %>
E. <%int i = 1%>
<%= i; %>
d. When using scriptlets (that is code included within <% %>), the included code must have legal Java syntax. So the first statement must end with a semi-colon. The second statement on the other hand is a JSP expression. So it must not end with a semi colon.

2. A JSP page called test.jsp is passed a parameter name in the URL using http://localhost/test.jsp?name="John". The test.jsp contains the following code.

<%! String myName=request.getParameter();%>
<% String test= "welcome" + myName; %>
<%= test%>
A. The program prints "Welcome John"
B. The program gives a syntax error because of the statement
<%! String myName=request.getParameter();%>
C. The program gives a syntax error because of the statement
<% String test= "welcome" + myName; %>
D. The program gives a syntax error because of the statement
<%= test%>
b. JSP declarations do not have access to automatically defined variables like request, response etc.

3. Which of the following correctly represents the following JSP statement. Select the one correct answer.
<%=x%>
A.
B. x
C. x
D. x
E. x

b. The XML syntax for JSP expression is Java expression

4. Which of the following correctly represents the following JSP statement. Select the one correct answer.
<%x=1;%>
A.
B. x=1;
C. x=1;
D. x=1;
E. x=1;
e. The XML syntax for JSP scriptlets is Java code

5. What gets printed when the following JSP code is invoked in a browser. Select the one correct answer.
<%= if(Math.random() < 0.5) %>
hello
<%= } else { %>
hi
<%= } %>

A. The browser will print either hello or hi based upon the return value of random.
B. The string hello will always get printed.
C. The string hi will always get printed.
D. The JSP file will not compile.
d. The if statement, else statement and closing parenthesis are JSP scriptlets and not JSP expressions. So these should be included within <% } %>

6. Which of the following are correct. Select the one correct answer.
A. JSP scriptlets and declarations result in code that is inserted inside the _jspService method.
B. The JSP statement <%! int x; %> is equivalent to the statement int x;.
C. The following are some of the predefined variables that maybe used in JSP expression - httpSession, context.
D. To use the character %> inside a scriptlet, you may use %\> instead.
d. JSP declarations are inserted outside of _jspService method. Hence a is incorrect. The JSP statement <%!int a;%> is equivalent to int x;. Hence b is incorrect. The predefined variables that are available within the JSP expression are session and pageContext, and not httpSession and context. Hence c is incorrect.

7. What gets printed when the following is compiled. Select the one correct answer.
<% int y = 0; %>
<% int z = 0; %>

<% for(int x=0;x<3;x++) { %>
<% z++;++y;%>
<% }%>

<% if(z
<%= z%>
<% } else {%>
<%= z - 1%>
<% }%>

A. 0
B. 1
C. 2
D. 3
E. The program generates compilation error.
c. After the for loop z and y are both set to 3. The else satement gets evaluated, and 2 gets printed in the browser.

8. Which of the following JSP variables are not available within a JSP expression. Select the one correct answer.
A. out
B. session
C. request
D. response
E. httpsession
F. page
e. There is no such variable as httpsession.

9. A bean with a property color is loaded using the following statement

Which of the following statements may be used to print the value of color property of the bean. Select the one correct answer.
A.
B.
C.
D.
E.
jsp:getProperty takes two attributes - name and property. The name attribute must match the id attribute of jsp:usebean.

10. A bean with a property color is loaded using the following statement

Which of the following statements may be used to set the of color property of the bean. Select the one correct answer.
A.
B.
C.
D.
E.
F.
e. The jsp:setProperty takes three attributes - name, property and value. Also the jsp:setProperty must end with />.

11. A bean with a property color is loaded using the following statement

What happens when the following statement is executed. Select the one correct answer.

A. This is incorrect syntax of and will generate a compilation error. Either value or param must be defined.
B. All the properties of the fruit bean are initialized to a value of null.
C. All the properties of the fruit bean are assigned the values of input parameters of the JSP page that have the same name.
D. All the properties of the fruit bean are initialized to a value of *.
c. Using * for property is legal syntax. Bean properties are associated with identically named input parameters.

12. Is the following statement true or false. If the isThreadSafe attribute of the page directive is false, then the generated servlet implements the SingleThreadModel interface.
true. The page directive is defined as <%@page isThreadSafe="false"%>


13. Which of the following represents a correct syntax for usebean. Select the two correct answers.
A.
B.
C.
D.
b,c.

14. Name the default value of the scope atribute of .
A. page
B. application
C. session
D. request
a. The default scope of the declared bean is page.



15. Which of the following statements are true for . Select the two correct answers.

A. The id attribute must be defined for .
B. The scope attribute must be defined for .
C. The class attribute must be defined for .
D. The must include either type or class attribute or both.

a,d. The scope and class attributes are not required. But either class or type must be defined.
16. Which of these are legal attributes of page directive. Select the two correct answers.
A. include
B. scope
C. errorPage
D. session
E. debug
c,d. The following are legal attributes of page directive - import, isThreadSafe, session, contentType, autoFlush, extends, info, errorPage, isErrorPage, language.

17. Which of the following represents the XML equivalent of this statement <%@ include file="a.jsp"%> . Select the one correct statement
A.
B.
C.
D. There is no XML equivalent of include directive.
c. is the XML equivalent of include directive.

18. Assume that you need to write a JSP page that adds numbers from one to ten, and then print the output.
<% int sum = 0;
for(j = 0; j < 10; j++) { %>
// XXX --- Add j to sum
<% } %>
// YYY --- Display ths sum

Which statement when placed at the location XXX can be used to compute the sum. Select the one correct statement
A. <% sum = sum + j %>
B. <% sum = sum + j; %>
C. <%= sum = sum + j %>
D. <%= sum = sum + j; %>

b. As this is a a Java statement it needs to be included with <% and %>, and it needs to end in semi-colon.
19. Now consider the same JSP example as last question. What must be added at the location YYY to print the sum of ten numbers. Select the one correct statement
A. <% sum %>
B. <% sum; %>
C. <%= sum %>
D. <%= sum; %>
c. As this is a a Java expression it needs to be included with <%= and %>, and it should not end in semi-colon.

20. JSP pages have access to implicit objects that are exposed automatically. One such object that is available is request. The request object is an instance of which class?

A. HttpRequest
B. ServletRequest
C. Request
D. HttpServletRequest
d. request is an instance of HttpServletRequest

21. JSP pages have access to implicit objects that are exposed automatically. Name the implicit object that is of type HttpSession.

A. session
B. application
C. httpSession
D. httpsession
a. Implicit object session is of type HttpSession.

22. A Java bean with a property color is loaded using the following statement

What is the effect of the following statement.

Select the one correct answer.
A. An error gets generated because the value attribute of setAttribute is not defined.
B. The color attribute is assigned a value null.
C. The color attribute is assigned a value "".
D. If there is a non-null request parameter with name color, then its value gets assigned to color property of Java Bean fruit.
d. This is a legal syntax to set a property of JavaBean. The value attribute of setProperty is optional.

23. The page directive is used to convey information about the page to JSP container. Which of these are legal syntax of page directive. Select the two correct statement
A. <% page info="test page" %>
B. <%@ page info="test page" session="false"%>
C. <%@ page session="true" %>
D. <%@ page isErrorPage="errorPage.jsp" %>
E. <%@ page isThreadSafe=true %>
b,c. The option a is incorrect because page directive must be included within <%@ . d is incorrect because the value of isErrorPage attribute must be boolean. e is incorrect because, the value true is not within quotes.

24. Is the following JSP code legal? Select the one correct statement.
<%@page info="test page" session="false"%>
<%@page session="false"%>
A. Yes. This is legal JSP syntax.
B. No. This code will generate syntax errors.
b. Except the import attribute of page directive, all the other attributes of page directive cannot be specified more than once. In this example session attribute is specified twice.

25. A JSP page needs to generate an XML file. Which attribute of page directive may be used to specify that the JSP page is generating an XML file.

A. contentType
B. generateXML
C. type
D. outputXML
a. contentType attribute is used to generate XML. The syntax will look like -
<%@page contentType="text/xml"/>

26. A JSP page uses the java.util.ArrayList class many times. Instead of referring the class by its complete package name each time, we want to just use ArrayList. Which attribute of page directive must be specified to achieve this. Select the one correct answer.

A. extends
B. import
C. include
D. package
E. classpath
B. The syntax will look like -
<%@page import="java.util.ArrayList"/>

27. Which of these are true. Select the two correct answers.

A. The default value of isThreadSafe attribute of page directive is true.
B. If isThreadSafe attribute of page directive is set to true, then JSP container dispatches request for the page sequentially.
C. When isThreadSafe attribute of page directive is set to true, a thread is created for each request for the page.
D. Setting isThreadSage attribute to true for JSP pages, can lead to poor performance.
a,c. The default value of isThreadSafe attribute is true. So a is correct. If isThreadSafe is set to false, then JSP container processes request sequentially, and this leads to poor performance. Hence b and d are incorrect.

28. Which of the following are examples of JSP directive. Select the two correct answers.
A. include
B. exclude
C. import
D. taglibrary
E. servlet
F. page
a,f. include, taglib and page are examples of JSP directives. The JSP directives have this syntax -
<%@directive attribute="value" %>

29. Which of these is true about include directive. Select the one correct answer.
A. The included file must have jspf extension.
B. The XML syntax of include directive in .
C. The content of file included using include directive, cannot refer to variables local to the original page.
D. When using the include directive, the JSP container treats the file to be included as if it was part of the original file.
d. It is not required that the included file has jspf extension. Hence a is incorrect. The XML syntax of include directive is

30. Name the implicit variable available to JSP pages that may be used to access all the other implicit objects.
A. page
B. pageContext
C. context
D. object
E. jspPave
b. This pageContext object is an instance of type javax.servlet.jsp.PageContext , and provides methods like getPage(), getRequest() , etc. to access other input variables.






------------------------------------------------------------------------- ------------------------








Questions on tag library
1. When implementing a tag, if the tag just includes the body verbatim, or if it does not include the body, then the tag handler class must extend the BodyTagSupport class. Is this statement true of false.



2. Fill in the blanks. A tag handler class must implement the javax.servlet.jsp.tagext.Tag interface. This is accomplished by extending the class TagSupport or another class named in one of the options below. Select the one correct answer.

A. IterationTag
B. TagClass
C. BodyTag
D. BodyTagSupport



3. Is this statement true or false. The deployment descriptor of a web application must have the name web.xml . In the same way the tag library descriptor file must be called taglib.xml .



4. A JSP file that uses a tag library must declare the tag library first. The tag library is defined using the taglib directive - <%= taglib uri="..." prefix="..."%>
Which of the following specifies the correct purpose of prefix attribute. Select the one correct answer.
A. The prefix defines the name of the tag that may be used for a tag library.
B. The prefix attribute defines the location of the tag library descriptor file.
C. The prefix attribute should refer to the short name attribute of the tag library file that is defined by the uri attribute of taglib directive.
D. The prefix attribute is used in front of a tagname of a tag defined within the tag library.


5. A JSP file uses a tag as . The myTag element here should be defined in the tag library descriptor file in the tag element using which element. Select the one correct answer.
A. tagname
B. name
C. tag
D. prefix


6. Which of the elements defined within the taglib element of taglib descriptor file are required. Select the two correct answers.
A. tlib-version
B. short-name
C. uri
D. display-name


7. Which of the elements defined within the taglib element of taglib descriptor file are required. Select the two correct answers.
A. name
B. description
C. validator
D. tag-class
E. display-name


8. Name the element within the tag element that defines the name of the class that implements the functionality of tag. Select the one correct answer.

A. class-name
B. tag
C. class
D. tag-class
E. tei-class


9. Which of these are legal return types of the doStartTag method defined in a class that extends TagSupport class. Select the two correct answers.
A. EVAL_PAGE
B. EVAL_BODY
C. EVAL_PAGE_INCLUDE
D. EVAL_BODY_INCLUDE
E. SKIP_PAGE
F. SKIP_BODY
G. SKIP_PAGE_INCLUDE
H. SKIP_BODY_INCLUDE


10. Which of these are legal return types of the doAfterBody method defined in a class that extends TagSupport class. Select the two correct answers.
A. EVAL_PAGE
B. EVAL_BODY
C. EVAL_PAGE_AGAIN
D. EVAL_BODY_AGAIN
E. SKIP_PAGE
F. SKIP_BODY
G. SKIP_PAGE_AGAIN
H. SKIP_BODY_AGAIN


11. Which of these are legal return types of the doEndTag method defined in a class that extends TagSupport class. Select the two correct answers.
A. EVAL_PAGE
B. EVAL_BODY
C. EVAL_PAGE_INCLUDE
D. EVAL_BODY_INCLUDE
E. SKIP_PAGE
F. SKIP_BODY
G. SKIP_PAGE_INCLUDE
H. SKIP_BODY_INCLUDE



Answers to questions on tag library
1. false. Such a class should extend the TagSupport class.
2. D. BodyTagSupport extends TagSupport and implements interfaces Tag and IterationTag.
3. false. The tag library descriptor file can have any name. It need not have the name taglib.xml .
4. d. If the taglib directive directive defines a prefix of test, and a tag is called myTag, then the tag is used as .
5. b. The name element inside the tag element defines the tag name to which the prefix of the taglib is attached. For example myTag
6. a,b. tlib-version and short-name are required elemets within the taglib element of the the tag library descriptor file.
7. a,d. name and tag-class are required elements within the tag element of tag library descriptor file.
8. d. tag-class element defines the fully qualified class name of the tag in the TLD file.
9. d,f. EVAL_BODY_INCLUDE, and SKIP_BODY are legal return types of doStartTag.
10. d,f. EVAL_BODY_AGAIN, and SKIP_BODY are legal return types of doAfterBody.
11. a,e. EVAL_PAGE and SKIP_PAGE are legal return types of doEndTag

Your Ad Here
Custom Search