You are on page 1of 39

SCWCD exam SCWCD FAQ Other SCWCD sites SCWCD Books Java News Java Jobs About Java

Prepare

Tutorial

Page Directive Include Directive Taglib Directive Declaration Scriptlet Expression Implicit Objects Comments Action

Questions

DD JSP Taglibs Servlets

EL and JSTL

Advertisements

javaprepare.com your tool for Java Certification

SCWCD home | SCWCD questions | SCWCD links | SCJP home javaprepare.com - Questions on Deployment Descriptor Which of the following files is the correct name and location of deployment descriptor of a web application. Assume that the web application is rooted at \doc-root. Select the one correct answer \doc-root\dd.xml \doc-root\web.xml \doc-root\WEB-INF\web.xml \doc-root\WEB_INF\dd.xml \doc-root\WEB-INF\dd.xml \doc-root\WEB_INF\web.xml \doc-root\WEB-INF\lib\dd.xml \doc-root\WEB-INF\classes\dd.xml

Which element of the servlet element in the deployment descriptor is used to specify the parameters for the ServletConfig object. Select the one correct answer. servlet-config init-param load-on-startup

filter

Which of these is true about deployment descriptors. Select the one correct answer. The order of elements in deployment descriptor is not important. The elements can follow any order. The elements of deployment descriptor are case insensitive. The servlet-mapping element, if defined, must be included within the servlet element. The web-app element must include the servlet element.

The exception-type element specifies an exception type and is used to handle exceptions generated from a servlet. Which element of the deployment descriptor includes the exception-type as a subelement. Select the one correct answer. error-page servlet exception error-handling

Which of these is a correct fragment within the web-app element of deployment descriptor. Select the one correct answer. <exception> <exception-type> mypackage.MyException</exception-type> <location> /error.jsp</location> </exception> <error-page> <exception-type> mypackage.MyException</exception-type> <location> /error.jsp</location> </error-page>

<error-page> <exception> mypackage.MyException </exception-type> <location> /error.jsp </location> </error-page>

<listener>MyClass</listener> <listener> <listener-class>MyClass</listener-class></listener> .jsp</location> </error-page> Which of these is a correct example of specifying a listener element resented by MyClass class.MyException</exception-type> <error-code>404</errorcode> <location>/error.jsp</location> </error-page> <error-page> <exception-type>mypackage.MyException</exception-type> </error-page> <error-page> <servlet-name> myservlet</servlet-name> <exception-type> mypackage.jsp</location> </error-page> <error-page> <exception-type>mypackage. web-app welcome-file servlet file-list Which of these is a correct fragment within the web-app element of deployment descriptor.MyException</exception-type> <location>/error.<error-page> <exception-type> mypackage.MyException</exception-type> </exception> Which element of the deployment descriptor of a web application includes the welcome-file-list element as a subelement.MyException</exception-type> </error-page> <exception> <servlet-name> myservlet</servlet-name> <exception-type> mypackage.MyException</exception-type> <error-code>404</errorcode> </error-page> <error-page> <exception-type>mypackage. Select the one correct answer. Select the one correct answer. Assume myServlet element is defined correctly. Select the two correct answer. <error-page> <error-code>404</error-code> <location>/error.

which of the following element is required? param-name name init-param servlet-name Which of these is not a valid top level element in web-app icon listener eror-page security-constraint param-name .<listener> <listener-name>aListener</listener-name> <listener-class>MyClass</listener-class> </listener> <listener> <servlet-name>myServlet</servlet-name> <listener-class>MyClass</listener-class> </listener> The root of the deployment descriptor is named as web web-app name display-name With in a context-param element of deployment descriptor.

Select the one correct answer. Select the one correct answer. FORWARD RESPONSE INCLUDE ERROR Which of these is not correct about the filter-mapping element of web-app. dispatcher element can be declared zero to three times in the filter-mapping element. Either url-pattern or servlet-name must be present in the filter-mapping element. filter-name name value filter-class init-param Which of these is not a valid value for dispatcher element of filter-mapping. Select two correct answers.Which of the follwing are mandatory elements within the filter element. Answers to questions on Deployment Descriptor . filter-name element must be present in the filter-mapping element. filter-name element in the filter-mapping should be same as the corresponding filter-name element in the filter element of deployment descriptor.

param-name is a child of context-param element. The four possible values of the dispatcher element are . All the elements within the web-app element are optional. welcome-file-list is included within the web-app element. It must also include the location element. b. B. B is incorrect because elements are case-sensitive. The deployment descriptor must be called web. E. init-param is used to specify parameters that are accessed using ServletConfig object. INCLUDE. SCWCD home | SCWCD questions | SCWCD links | SCJP home Questions on tag library . The servlet-mapping element should be included within the <web-app> element. So D is incorrect. In the deployment descriptor the elements in the web-app element can come in any order. <web-app> element is the root of the deployment descriptor. RESPONSE is not a value for the dispatcher element. The error-page element includes exception-type and location as sub-element. The element listener-class must be included within the listener element. B. param-name and param-value are required within the context-param element. A. error-page element must include either exception-type or error-code element but not both. It has one attribute named version. A and D. filter-name and filter-class are required elements of the filter element. B.xml and be placed in the directory named WEBINF B.D. error-page element in the element web-app element is used to specify the exception name. a.FORWARD. So C is incorrect. REQUEST and ERROR. A. C. A. A.C. Both these elements must be defined. dispatcher element can be declared upto four times.

Is this statement true or false. The prefix attribute defines the location of the tag library descriptor file. Select the one correct answer. BodyTag D. prefix 6.. A. BodyTagSupport 3. Fill in the blanks.tagext. Which of the elements defined within the taglib element of taglib descriptor file are required. 5. then the tag handler class must extend the BodyTagSupport class. C.<%= taglib uri=". Select the two correct answers. The myTag element here should be defined in the tag library descriptor file in the tag element using which element.jsp.. IterationTag B.servlet. 4.xml . tagname B."%> Which of the following specifies the correct purpose of prefix attribute. . if the tag just includes the body verbatim. tag D. The tag library is defined using the taglib directive .1. A. 2. TagClass C. Is this statement true of false. This is accomplished by extending the class TagSupport or another class named in one of the options below. name C. When implementing a tag. or if it does not include the body. The prefix defines the name of the tag that may be used for a tag library. A JSP file that uses a tag library must declare the tag library first.. B. Select the one correct answer. A. 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. A JSP file uses a tag as <myTaglib:myTag>. In the same way the tag library descriptor file must be called taglib. A tag handler class must implement the javax.. Select the one correct answer. The prefix attribute is used in front of a tagname of a tag defined within the tag library." prefix=".xml .Tag interface. D. The deployment descriptor of a web application must have the name web.

SKIP_PAGE F. Name the element within the tag element that defines the name of the class that implements the functionality of tag. E. B. display-name 8. C. SKIP_BODY G. Which of these are legal return types of the doAfterBody method defined in a class that extends TagSupport class. Which of these are legal return types of the doStartTag method defined in a class that extends TagSupport class. A. EVAL_BODY C. description C. class-name tag class tag-class tei-class 9.A. EVAL_PAGE B. A. Select the two correct answers. EVAL_BODY C. tlib-version short-name uri display-name 7. validator D. A. Select the one correct answer. Select the two correct answers. Which of the elements defined within the taglib element of taglib descriptor file are required. C. EVAL_PAGE_AGAIN . D. SKIP_PAGE_INCLUDE H. A. name B. D. Select the two correct answers. tag-class E. EVAL_PAGE_INCLUDE D. EVAL_BODY_INCLUDE E. EVAL_PAGE B. SKIP_BODY_INCLUDE 10. B.

SKIP_BODY G. tlib-version and short-name are required elemets within the taglib element of the the tag library descriptor file. then the tag is used as <test:myTag>. name and tag-class are required elements within the tag element of tag library descriptor file. Which of these are legal return types of the doEndTag method defined in a class that extends TagSupport class. EVAL_PAGE_INCLUDE D. EVAL_BODY_INCLUDE. SKIP_BODY_INCLUDE Answers to questions on tag library 1. false.e. 7. b. d. and a tag is called myTag. The tag library descriptor file can have any name. For example <name> myTag </name> 6.f.xml . EVAL_PAGE B. a. 3.b. 11. 8. It need not have the name taglib.D.d. 5. d. SKIP_PAGE F. EVAL_BODY_INCLUDE E. Select the two correct answers. EVAL_BODY_AGAIN SKIP_PAGE SKIP_BODY SKIP_PAGE_AGAIN SKIP_BODY_AGAIN 11. The name element inside the tag element defines the tag name to which the prefix of the taglib is attached.com SCWCD exam your tool for Java Certification .f. and SKIP_BODY are legal return types of doAfterBody. F. EVAL_PAGE and SKIP_PAGE are legal return types of doEndTag javaprepare. A. Such a class should extend the TagSupport class. EVAL_BODY_AGAIN. tag-class element defines the fully qualified class name of the tag in the TLD file. false. 2. D. BodyTagSupport extends TagSupport and implements interfaces Tag and IterationTag. and SKIP_BODY are legal return types of doStartTag. 4. a. SKIP_PAGE_INCLUDE H. G. a. d. E. H. 10. EVAL_BODY C. d. If the taglib directive directive defines a prefix of test. 9.

%> D.getParameter(). Which of the following correctly represents the following JSP statement. %> <%= test%> A.%> 1%> Page Directive Include Directive Taglib Directive Declaration Scriptlet Expression Implicit Objects Comments Action Questions DD JSP Taglibs Servlets EL and JSTL Advertisements 2.%> C. <%int i = <%= i %> E. as compared to these set of questions.SCWCD FAQ Other SCWCD sites SCWCD Books Java News Java Jobs About Java Prepare Tutorial SCWCD home | SCWCD questions | SCWCD links | SCJP home javaprepare.%> <% String test= "welcome" + myName. The test. <jsp:declaration>x</jsp:declaration> E. Also the real exam questions will probably be more difficult than these questions.com .jsp is passed a parameter name in the URL using http://localhost/test. <%int i = <%= i %> D. Select the one correct answer A. <jsp:scriptlet>x</jsp:scriptlet> . 1. %> C. %> B.Questions on JSP A small note here .getParameter(). <jsp:statement>x</jsp:statement> D. Which of the following is legal JSP syntax to print the value of i.jsp?name="John". The program gives a syntax error because of the statement <%= test%> 3. 1%> 1. The program gives a syntax error because of the statement <% String test= "welcome" + myName. A JSP page called test.%> 1. <jsp:expression=x/> B. there will be less questions of type fill in the blanks. <jsp:expression>x</jsp:expression> C. <%int i = i. The program gives a syntax error because of the statement <%! String myName=request.jsp contains the following code.In the real exam. <%=x%> A. %> 1. <%! String myName=request. <%int i = <%= i. The program prints "Welcome John" B. Select the one correct answer. <%int i = <%= i.

<jsp:statement>x=1. <% int y = 0. %> <% for(int x=0. The string hi will always get printed.</jsp:expression> C. <jsp:expression x=1.</jsp:declaration> E. D. The JSP statement <%! int x. <jsp:expression>x=1. <%= if(Math./> B.4. Which of the following correctly represents the following JSP statement. The browser will print either hello or hi based upon the return value of random. Select the one correct answer. %> is equivalent to the statement <jsp:scriptlet>int x.random() < 0. <jsp:scriptlet>x=1.5) %> hello <%= } else { %> hi <%= } %> A.++y. you may use %\> instead. D. The following are some of the predefined variables that maybe used in JSP expression .%> A. Select the one correct answer. 6. The string hello will always get printed.</jsp:scriptlet%>.x<3.</jsp:scriptlet> 5. Select the one correct answer. A.x++) { %> <% z++. <jsp:declaration>x=1. What gets printed when the following is compiled. Which of the following are correct. To use the character %> inside a scriptlet. C.</jsp:statement> D. B.%> <% }%> <% if(z<y) {%> <%= z%> <% } else {%> . The JSP file will not compile. What gets printed when the following JSP code is invoked in a browser. JSP scriptlets and declarations result in code that is inserted inside the _jspService method. C. 7. context.httpSession. %> <% int z = 0. <%x=1. B. Select the one correct answer.

A bean with a property color is loaded using the following statement <jsp:usebean id="fruit" class="Fruit"/> Which of the following statements may be used to set the of color property of the bean. <jsp:setColor id="fruit" property="color" value="white"/> B. A. <jsp:setProperty name="fruit" property="color" . Which of the following JSP variables are not available within a JSP expression. E. <jsp:setProperty name="fruit" property="color" value="white"> E. httpsession F. <jsp:setValue name="fruit" property="color" value="white"/> D. 0 1 2 3 The program generates compilation error. 10. page 9. A bean with a property color is loaded using the following statement <jsp:usebean id="fruit" class="Fruit"/> Which of the following statements may be used to print the value of color property of the bean. request D. out B. D.<%= z . Select the one correct answer. <jsp:getColor bean="fruit"/> <jsp:getProperty id="fruit" property="color"/> <jsp:getProperty bean="fruit" property="color"/> <jsp:getProperty name="fruit" property="color"/> <jsp:getProperty class="Fruit" property="color"/> E. session C. C. B. D. Select the one correct answer. Select the one correct answer. <jsp:setColor name="fruit" property="color" value="white"/> C. 8. A. C. A.1%> <% }%> A. response E. B.

request . Select the two correct answers. If the isThreadSafe attribute of the page directive is false. All the properties of the fruit bean are initialized to a value of *. Name the default value of the scope atribute of <jsp:usebean>. All the properties of the fruit bean are assigned the values of input parameters of the JSP page that have the same name. <jsp:usebean id="fruit scope ="page"/> B.value="white"/> F. Select the one correct answer. Either value or param must be defined. <jsp:usebean id="fruit class="Fruit" beanName="Fruit"/> 14. All the properties of the fruit bean are initialized to a value of null. Is the following statement true or false. application C. then the generated servlet implements the SingleThreadModel interface. D. 12. 13. <jsp:usebean id="fruit type ="String"/> C. A bean with a property color is loaded using the following statement <jsp:usebean id="fruit" class="Fruit"/> What happens when the following statement is executed. B. Which of the following represents a correct syntax for usebean. C. <jsp:setProperty id="fruit" property="color" value="white"> 11. session D. <jsp:setProperty name="fruit" property="*"/> A. This is incorrect syntax of <jsp:setProperty/> and will generate a compilation error. <jsp:usebean id="fruit type ="String" beanName="Fruit"/> D. A. A. page B.

<jsp:directive. <jsp:include page="a. Select the two correct answers. 16. Select the one correct statement A. The id attribute must be defined for <jsp:usebean>. Which of these are legal attributes of page directive. Assume that you need to write a JSP page that adds numbers from one to ten.jsp"%> . 18. j < 10. include B. j++) { %> Add j to sum Display ths sum Which statement when placed at the location XXX can be used to compute the sum. The class attribute must be defined for <jsp:usebean>. // XXX --<% } %> // YYY --= 0. The scope attribute must be defined for <jsp:usebean>. Select the two correct answers.jsp"/> C.15. <% sum = sum + j. The <jsp:usebean> must include either type or class attribute or both. session E. <jsp:include file="a. Select the one correct statement A. <% sum = sum + j %> B. C. Which of the following statements are true for <jsp:usebean>. %> . Which of the following represents the XML equivalent of this statement <%@ include file="a.jsp"/> B. A. debug 17.jsp"/> D. B. scope C. errorPage D. There is no XML equivalent of include directive.include file="a. D. <% int sum for(j = 0. A. and then print the output.

A. Name the implicit object that is of type HttpSession. Select the one correct statement A. The color attribute is assigned a value null. . If there is a non-null request parameter with name color. <%= sum = sum + j. JSP pages have access to implicit objects that are exposed automatically. D. HttpRequest ServletRequest Request HttpServletRequest 21. Now consider the same JSP example as last question. httpSession D. JSP pages have access to implicit objects that are exposed automatically. application C. B. <%= sum %> D.C. The color attribute is assigned a value "". %> 19. %> C. A Java bean with a property color is loaded using the following statement <jsp:usebean id="fruit" class="Fruit"/> What is the effect of the following statement. The request object is an instance of which class? A. %> 20. C. A. session B. <%= sum. httpsession 22. One such object that is available is request. <% sum. C. B. <jsp:setproperty name="fruit" property="color"/> Select the one correct answer. An error gets generated because the value attribute of setAttribute is not defined. <%= sum = sum + j %> D. <% sum %> B. D. What must be added at the location YYY to print the sum of ten numbers.

import C.jsp" %> E. Which attribute of page directive may be used to specify that the JSP page is generating an XML file. Select the one correct answer. A JSP page needs to generate an XML file.then its value gets assigned to color property of Java Bean fruit. This code will generate syntax errors. Which of these are legal syntax of page directive. <%@page info="test page" session="false"%> <%@page session="false"%> A. Select the two correct statement A. The page directive is used to convey information about the page to JSP container. we want to just use ArrayList.util. 23. include D. Is the following JSP code legal? Select the one correct statement. Yes.ArrayList class many times. <%@ page isErrorPage="errorPage. <%@ page session="true" %> D. A JSP page uses the java. extends B. <%@ page isThreadSafe=true %> 24. <% page info="test page" %> B. contentType generateXML type outputXML 26. No. B. <%@ page info="test page" session="false"%> C. A. B. C. Instead of referring the class by its complete package name each time. classpath . 25. A. package E. D. Which attribute of page directive must be specified to achieve this. This is legal JSP syntax.

When using the include directive. 28. include B. a thread is created for each request for the page. 30. pageContext C. D. The default value of isThreadSafe attribute of page directive is true. B. Which of these is true about include directive. A. The XML syntax of include directive in <jsp:include file="fileName"/> . Select the two correct answers. C. When isThreadSafe attribute of page directive is set to true. Which of these are true. servlet F. object E. The included file must have jspf extension. Setting isThreadSage attribute to true for JSP pages. Select the two correct answers. cannot refer to variables local to the original page. Name the implicit variable available to JSP pages that may be used to access all the other implicit objects. exclude C. Which of the following are examples of JSP directive. taglibrary E. page 29. Select the one correct answer. jspPave . A. If isThreadSafe attribute of page directive is set to true. The content of file included using include directive. page B. C. A.27. the JSP container treats the file to be included as if it was part of the original file. context D. import D. A. D. then JSP container dispatches request for the page sequentially. B. can lead to poor performance.

d. The else satement gets evaluated. 9. The name attribute must match the id attribute of jsp:usebean.include> is the XML equivalent of include directive.</jsp:declaration>. The XML syntax for JSP scriptlets is <jsp:scriptlet>Java code</jsp:scriptlet> 5. property and value. and not httpSession and context. the included code must have legal Java syntax. and it should not end in semi-colon. b. The jsp:setProperty takes three attributes . 3. Hence b is incorrect. Hence c is incorrect. 16. jsp:getProperty takes two attributes . 19. 2. The page directive is defined as <%@page isThreadSafe="false"%> 13. The XML syntax for JSP expression is <jsp:expression>Java expression</jsp:expression> 4.import. When using scriptlets (that is code included within <% %>). a.%> is equivalent to <jsp:declaration>int x. e. 20. The following are legal attributes of page directive . But either class or type must be defined. The default scope of the declared bean is page. true. contentType. response etc. Also the jsp:setProperty must end with />. As this is a a Java statement it needs to be included with <% and %>. 17. a. After the for loop z and y are both set to 3. The second statement on the other hand is a JSP expression. Hence a is incorrect. c. 7. language. 8. c. As this is a a Java expression it needs to be included with <%= and %>. e. else statement and closing parenthesis are JSP scriptlets and not JSP expressions. The predefined variables that are available within the JSP expression are session and pageContext. c. d.name and property. JSP declarations are inserted outside of _jspService method. JSP declarations do not have access to automatically defined variables like request. 14. info. d. The JSP statement <%!int a. 11. <jsp:directive. So it must not end with a semi colon. 12. 18. extends. b. Using * for property is legal syntax. c.Answers to questions on JSP 1. So the first statement must end with a semi-colon. The if statement. autoFlush.name. The scope and class attributes are not required. and it needs to end in semi-colon. request is an instance of HttpServletRequest . b.c. There is no such variable as httpsession. 10. e. d. So these should be included within <% } %> 6. session. b.d. and 2 gets printed in the browser. d. errorPage. isErrorPage. Bean properties are associated with identically named input parameters. isThreadSafe. c. 15.

Which of these classes define the getWriter method? Select the one correct answer. then JSP container processes request sequentially. etc. b.Questions on Servlets 1. 25.c. and this leads to poor performance. ServletConfig D. e is incorrect because.f. the value true is not within quotes. all the other attributes of page directive cannot be specified more than once. include. Select the one correct answer. Hence a is incorrect.include> 30. to access other input variables. d is incorrect because the value of isErrorPage attribute must be boolean.c. In this example session attribute is specified twice. getRequest(). The JSP directives have this syntax <%@directive attribute="value" %> 29. 24. a.util. HttpServletRequest B.21. This pageContext object is an instance of type javax. The default value of isThreadSafe attribute is true. So a is correct. If isThreadSafe is set to false. a. SCWD home | SCWD questions | SCWD links | SCJP home javaprepare. Implicit object session is of type HttpSession. 22.servlet. Except the import attribute of page directive.com . taglib and page are examples of JSP directives. HttpServletResponse C. 28. The XML syntax of include directive is <jsp:directive. . A. The syntax will look like <%@page contentType="text/xml"/> 26. contentType attribute is used to generate XML. Name the method defined in the HttpServletResponse class that may be used to set the content type. Hence b and d are incorrect.jsp. The value attribute of setProperty is optional. The syntax will look like <%@page import="java. and provides methods like getPage(). This is a legal syntax to set a property of JavaBean. d. The method getWriter returns an object of type PrintWriter. b. ServletContext 2.PageContext. The option a is incorrect because page directive must be included within <%@ .ArrayList"/> 27. This class has println methods to generate output. a. b. B. It is not required that the included file has jspf extension. 23. a. d.

D. B. content type and the document. The sendError method defined in the HttpServlet class is equivalent to invoking the setStatus method with the following parameter. SC_OK SC_MOVED_TEMPORARILY SC_NOT_FOUND SC_INTERNAL_SERVER_ERROR ESC_BAD_REQUEST E. Which of the following statement is correct. The setStatus method defined in the HttpServletRequest class takes an int as an argument and sets the status of Http response D. A. The response from the server to a GET request does not contain a document. B. A. Which of the following statements are correct about the status of the Http response. B. SC_OK SC_MOVED_TEMPORARILY SC_NOT_FOUND SC_INTERNAL_SERVER_ERROR ESC_BAD_REQUEST E. A status of 500 to 599 indicates an error in the client. 5. 6. C. C.A. setType setContent setContentType setResponseContentType 3. Select the one correct answer. A status of 400 to 499 indicates an error in the server. D. C. A status of 300 to 399 are informational messages. B. The sendRedirect method defined in the HttpServlet class is equivalent to invoking the setStatus method with the following parameter and a Location header in the URL. . The response from the dedicated server to a HEAD request consists of status line. A status of 200 to 299 signifies that the request was successful. Select the one correct answer. The HttpServletResponse defines constants like SC_NOT_FOUND that may be used as a parameter to setStatus method. 4. A. C. C. Select the one correct answer. B. D. D. Select the one correct answer. A.

Which of the following are correct statements? Select the two correct answers. Select the one correct answer. D. Select the one correct answer. Is the following statement true or false. D. To send binary output in a response. URL rewriting may be used when a browser is disabled. the following method of HttpServletResponse may be used to get the appropriate Writer/Stream object. whereas the getRequestDispatcher method of HttpServletRequest class takes the path of the servlet relative to the ServletContext. HttpServletResponse C. HttpServletRequest B. B. A. The include method defined in the RequestDispatcher class can be used to access one servlet from another. C. The getRequestDispatcher(String URL) is defined in both ServletContext and HttpServletRequest method . B.7. C. But it can be invoked only if no output has been sent to the server. getStream getOutputStream getBinaryStream getWriter 8. getStream getOutputStream getBinaryStream getWriter 9. To send text output in a response. In URL encoding the session id is included as part of the URL. A. B. Name the class that includes the getSession method that is used to get the HttpSession object. C. 10. SessionContext D. A. SessionConfig 11. A. The getRequestDispatcher method of ServletContext class takes the full path of the servlet. the following method of HttpServletResponse may be used to get the appropriate Writer/Stream object.

A. 15. A. C. D. A. When using HTML forms which of the folowing is true for POST method? Select the one correct answer. A.D. Which of the following is not a valid HTTP/1.javaprepare. Select the one correct answer. HEAD method D. TRACE method 16. OPTIONS method D. PUT method 14. COMPARE method C. GET method B. The POST method should not be used when large amount of data needs to be transferred. Which HTTP request gets generated. GET method B.html . Select the one correct answer. Select the one correct answer. Which HTTP method gets invoked when a user clicks on a link? Select the one correct answer. POST method C. A user types the URL http://www.com/scwd/index. POST allows users to bookmark URLs with parameters. PUT method 13. Name the http method used to send resources to the server. HEAD method D. POST method C. B. The getNamedDispatcher(String) defined in HttpServletRequest class takes the name of the servlet and returns an object of RequestDispatcher class. 12. CONNECT method B. FTP methodd . POST allows secure data transmission over the http method. POST method sends data in the body of the request.1 method. A.

/WEB-INF/classes D. C. A. Codes starting from 300 C. COPY method 17. Codes starting from 200 B. B. The class HttpServletResponse defines the getWriter method. /root/classes Answers to questions on Servlets 1. Select the one correct answer. OPTIONS method D. The response from the server to a HEAD request does not contain the document. whereas the response to GET request does contain a document. /META-INF/classes B. C is incorrect because setStauts is defined in HttpServletResponse. Name the location of compiled class files within a war file? Select the one correct answer. A. A. D. Which three digit error codes represent an error in request from client? Select the one correct answer. DEBUG method B. 5. B. HEAD method 18. Codes starting from 500 19. PUT method C. WRITE method D. setContentType sets the content type of the response being sent to the client.B. /classes C. TRACE method C. 3. So A and B are incorrect. . Codes starting from 400 D. 2. B. Name the http method that sends the same response as the request. 4. sendError(String URL) is equivalent to sending SC_NOT_FOUND (404) response code. sendRedirect(String URL) is equivalent to sending SC_MOVED_TEMPORARILY (302) response code and a location header in the URL.

1 2 4 5 2. D. 18. D. Since arguments are present in the body of the request. PUT method is used to send resources from client to server. TRACE method is used for debugging. A. 8. B. 19. A. A. ${4 div 5} A. Questions on JSTL and EL 1. Since POST does not have attributes in the URL.6. The getOutputStream method is used to get an output stream to send binary data. What gets printed when the following expression is evaluated? Select the one correct answer. 7. 1 . B. B. 14. Classes are stored in /WEB-INF/classes. B. using POST method does not guarantee security. 11. B. The getWriter method is used to get a PrintWriter object that can be used to send text data. The following table specifies the specific the status code of Http response. Status Code Purpose 100-199 Informational 200-299 300-399 400-499 500-599 Request was successful Request file has moved. 15. A.8 C. 0. The statement about URL encoding is correct. 16. GET method gets invoked when a URL is typed. true. 0 B. C. 12. Client error Server error. What gets printed when the following expression is evaluated? Select the one correct answer. 13. A status code of 4XX represents a client error. C. It sends the same response as request. 17. D 9. ${(1==2) ? 4 : 5} A. COMPARE is not a valid HTTP method. The class HttpServletRequest defines the getSession method. C. C. GET method gets invoked when user clicks on a link. 10. A. it cannot be used to bookmark the URL.

B. 0 3 8 16 4. true false 25 The expression does not compile as ne is not a valid operator.D. B.Employee" scope="session"/> <jsp:setProperty name="employee" property="*"/> A. The code does not compile as property attribute cannot take * as a value.Employee" %> <jsp:useBean id="employee" class="classes. D. assuming a class with name Employee exists in classes package. C. What is the effect of evaluation of following expression? Select the one correct answer. ${'cat' gt 'cap'} A. What gets printed when the following expression is evaluated? Select the one correct answer. ${12 % 4} A. C. The code does not compile as there is no property attribute of setProperty tag. D. B. What is the effect of executing the following JSP statement. <%@ page import = "classes. 5. What is the effect of evaluation of following expression? Select the one correct answer. true B. ${(5*5) ne 25} A. false C. catcap . 6. C. D. The code sets the values of all properties of employee bean to matrching parameters in request object. The code sets value of all properties of employee bean to "*". -1 3.

B. <%@ taglib uri="http://java. 7. <%@ taglib uri="http://java.com/jsp/jstl/core" prefix="c" %> <c:set var="item" value="2"/> <c:if test="${var==1}" var="result" scope="session"> <c:out value="${result}"/> </c:if> A.sun. D.out statement does not get executed. 0 2 ABC Nothing gets printed as c. How many numbers are printed.com/jsp/jstl/core" prefix="c" %> <c:set var="item" value="2"/> <c:forEach var="item" begin="0" end="0" step="2"> <c:out value="${item}" default="abc"/> </c:forEach> A.sun. C. What gets printed when the following JSTL code fragment is executed? Select the one correct answer. B. C. D. when the following JSTL code fragment is executed? Select the one correct answer. What gets printed when the following JSTL code fragment is executed? Select the one correct answer. The JSTL code does not compile as an attribute for forEach tag is not correct. 1 5 6 11 8.com/jsp/jstl/core" prefix="c" %> <c:forEach var="item" begin="0" end="10" step="2"> ${item} </c:forEach> A. C. 9. The expression does not compile as gt operator cannot be applied on strings. The JSTL code does not compile as attribute for if tag are not correct.sun. D. B. . true false Nothing gets printed. <%@ taglib uri="http://java.D. E.

1 2 3 4 abc The program does not compile. C. <%@ taglib uri="http://java. Three numbers gets printed.sun. E. B.com/jsp/jstl/core" prefix="c" %> <c:set var="j" value="4. F.10. . How many numbers gets printed when the following JSTL code fragment is executed? Select the one correct answer.sun. D.com/jsp/jstl/core" prefix="c" %> <c:set var="item" value="2"/> <c:choose> <c:when test="${item>0}"> <c:out value="1"/> </c:when> <c:when test="${item==2}"> <c:out value="2"/> </c:when> <c:when test="${item<2}"> <c:out value="3"/> </c:when> <c:otherwise> <c:out value="4"/> </c:otherwise> </c:choose> A. 11.3. D. Which numbers gets printed when the following JSTL code fragment is executed? Select the two correct answers. One number gets printed. B. Two numbers gets printed. C. E. 12. No number gets printed. Four numbers gets printed. <%@ taglib uri="http://java. Which numbers gets printed when the following JSTL code fragment is executed? Select the two correct answers.2.1"/> <c:forEach items="${j}" var="item" begin="1" end="2"> <c:out value="${item}" default="abc"/> </c:forEach> A.

http://java. B.com/jsp/jstl1. 5 gets printed.1"/> <c:forEach items="${j}" var="item" varStatus="status"> <c:if test="${status. Which of these represent the correct path for the core JSTL library in JSTL version 1. http://java.sun. A. Which number gets printed when the following JSTL code fragment is executed? Select the one correct answers. 1 2 3 4 abc The program does not compile. http://java.2. F.com/jsp/jstl/core" prefix="c" %> <c:set var="j" value="4.count}" default="abc"/> </c:forEach> A.com/jsp/jstl/core B. As 1 is not equal to 2. D. B.sun.index}" default="abc"/> </c:if> </c:forEach> A. . C.3.1/core Answers to questions on EL and JSTL 1. 2.1"/> <c:forEach items="${j}" var="item" begin="1" end="2" varStatus="status"> <c:out value="${status. B. div operator is used for dividing in EL.sun. 1 2 3 4 abc The program does not compile. D.first}"> <c:out value="${status. A.1? Select the one correct answer.sun.sun. 3. % operator gives the remainder after performing division. C. E. 13. D. F. 14. <%@ taglib uri="http://java.3.2.sun.com/jsp/jstl/core" prefix="c" %> <c:set var="j" value="4.<%@ taglib uri="http://java. http://java. E.com/jsp/core C.com/core D.

count is the loop index. C. <%int i = <%= i %> E. B. <%! String myName=request. Only one number gets printed .the number 1. This is a valid syntax for setProperty. <%int i = <%= i. ne is a valid operator. A. So for two iterations 1 and 2 get printed.first is true for the first iteration. B. false gets printed. B. and prints zero. The index is set to 0 in the first iteration. A JSP page called test.getParameter(). there will be less questions of type fill in the blanks. The following numbers get printed . B. 10. 6. 9.out statement does not get executed.jsp contains the following code.com/jsp/jstl/core . The test. <%int i = <%= i. status. 7. 5.%> 1. %> B. All properties of the bean are set from the corresponding parameter names in the request object.Questions on JSP A small note here . EL considers <cat> to be greater than <cap>. 12. Since both left hand side and right hand side are equal to 25. 2. This class has a property named count which is being printed. as the letter t comes after the letter p.jsp?name="John". In this case the forEach tag iterates through two elements of the array named j. Which of the following is legal JSP syntax to print the value of i. Select the one correct answer A. %> <%= test%> A. C. as compared to these set of questions. 4. The forEach tag gets executed once. 13. <%int i = <%= i %> D. 11. The path of core tag library in JSTL 1. beginning with 1. 10. hence the c. The code prints false. 14.com . The program prints "Welcome John" . if evaluates to false. 8.%> 1%> 2. 8.sun. B.4. C. D. 1. varStatus is set to a class of type LoopTagStatus.0.%> <% String test= "welcome" + myName.In the real exam. Also the real exam questions will probably be more difficult than these questions. D.jsp is passed a parameter name in the URL using http://localhost/test. 1%> 1.1 is http://java. A. %> C. SCWCD home | SCWCD questions | SCWCD links | SCJP home javaprepare. <%int i = i. A. In this case the forEach tag iterates through two elements of the array named j. 6. %> 1.

%> D. Select the one correct answer. The string hi will always get printed.</jsp:declaration> E. Select the one correct answer. Select the one correct answer. The string hello will always get printed. The program gives a syntax error because of the statement <%! String myName=request. What gets printed when the following JSP code is invoked in a browser. <%=x%> A. <jsp:statement>x=1. Select the one correct answer. <jsp:expression>x</jsp:expression> C.B. <jsp:declaration>x=1. The JSP file will not compile. D. <%= if(Math. The browser will print either hello or hi based upon the return value of random.%> A.random() < 0. <jsp:expression x=1. Which of the following are correct. B. . Which of the following correctly represents the following JSP statement. <jsp:expression=x/> B. <jsp:scriptlet>x=1./> B.%> C.</jsp:expression> C. <jsp:statement>x</jsp:statement> D. <%x=1. <jsp:scriptlet>x</jsp:scriptlet> 4. <jsp:expression>x=1. Which of the following correctly represents the following JSP statement. The program gives a syntax error because of the statement <% String test= "welcome" + myName. The program gives a syntax error because of the statement <%= test%> 3.</jsp:statement> D. 6. <jsp:declaration>x</jsp:declaration> E. C.</jsp:scriptlet> 5.5) %> hello <%= } else { %> hi <%= } %> A.getParameter().

Which of the following JSP variables are not available within a JSP expression. you may use %\> instead. C. A. E. httpsession F.++y.A. context.%> <% }%> <% if(z<y) {%> <%= z%> <% } else {%> <%= z . What gets printed when the following is compiled. The JSP statement <%! int x. 8.httpSession. 0 1 2 3 The program generates compilation error. session C. out B. <jsp:getProperty bean="fruit" property="color"/> . To use the character %> inside a scriptlet. Select the one correct answer.1%> <% }%> A. %> <% int z = 0. %> is equivalent to the statement <jsp:scriptlet>int x. request D.x++) { %> <% z++. <% int y = 0. B.</jsp:scriptlet%>. A. response E. D. Select the one correct answer. C. The following are some of the predefined variables that maybe used in JSP expression . A bean with a property color is loaded using the following statement <jsp:usebean id="fruit" class="Fruit"/> Which of the following statements may be used to print the value of color property of the bean. Select the one correct answer.x<3. <jsp:getColor bean="fruit"/> B. %> <% for(int x=0. 7. <jsp:getProperty id="fruit" property="color"/> C. D. page 9. B. JSP scriptlets and declarations result in code that is inserted inside the _jspService method.

<jsp:getProperty class="Fruit" property="color"/> 10. 12. All the properties of the fruit bean are assigned the values of input parameters of the JSP page that have the same name. Select the two correct answers. 11. B. B. 13. If the isThreadSafe attribute of the page directive is false. <jsp:getProperty name="fruit" property="color"/> E. page . <jsp:usebean id="fruit scope ="page"/> B. <jsp:usebean id="fruit type ="String" beanName="Fruit"/> D. D. then the generated servlet implements the SingleThreadModel interface. <jsp:setProperty name="fruit" property="*"/> A. A bean with a property color is loaded using the following statement <jsp:usebean id="fruit" class="Fruit"/> What happens when the following statement is executed. A. Select the one correct answer. Is the following statement true or false. C. All the properties of the fruit bean are initialized to a value of *. This is incorrect syntax of <jsp:setProperty/> and will generate a compilation error.D. A bean with a property color is loaded using the following statement <jsp:usebean id="fruit" class="Fruit"/> Which of the following statements may be used to set the of color property of the bean. <jsp:setColor id="fruit" property="color" value="white"/> <jsp:setColor name="fruit" property="color" value="white"/> <jsp:setValue name="fruit" property="color" value="white"/> <jsp:setProperty name="fruit" property="color" value="white"> <jsp:setProperty name="fruit" property="color" value="white"/> <jsp:setProperty id="fruit" property="color" value="white"> F. A. D. E. <jsp:usebean id="fruit class="Fruit" beanName="Fruit"/> 14. Select the one correct answer. All the properties of the fruit bean are initialized to a value of null. Name the default value of the scope atribute of <jsp:usebean>. <jsp:usebean id="fruit type ="String"/> C. Either value or param must be defined. A. Which of the following represents a correct syntax for usebean. C.

Which of the following represents the XML equivalent of this statement <%@ include file="a. Assume that you need to write a JSP page that adds numbers from one to ten. D. session E. A.B.include file="a.jsp"%> . Which of these are legal attributes of page directive. <jsp:include file="a. Select the one correct statement . j < 10. 18. Select the one correct statement A. The id attribute must be defined for <jsp:usebean>. Which of the following statements are true for <jsp:usebean>. There is no XML equivalent of include directive. session D. Select the two correct answers. j++) { %> Add j to sum Display ths sum Which statement when placed at the location XXX can be used to compute the sum.jsp"/> B. C. 16. A. B. debug 17. The class attribute must be defined for <jsp:usebean>. Select the two correct answers. request 15.jsp"/> D. The scope attribute must be defined for <jsp:usebean>. errorPage D. <jsp:include page="a.jsp"/> C. <% int sum for(j = 0. The <jsp:usebean> must include either type or class attribute or both. and then print the output. <jsp:directive. // XXX --<% } %> // YYY --= 0. include B. application C. scope C.

D. application C. httpsession 22. %> C. %> 19. <% sum. JSP pages have access to implicit objects that are exposed automatically. B. A. <%= sum. <jsp:setproperty name="fruit" property="color"/> Select the one correct answer. C. session B. Name the implicit object that is of type HttpSession. <% sum = sum + j %> <% sum = sum + j. then its value gets assigned to color property of Java Bean fruit. . The color attribute is assigned a value null. D. An error gets generated because the value attribute of setAttribute is not defined. %> 20. D. %> <%= sum = sum + j %> <%= sum = sum + j. One such object that is available is request. What must be added at the location YYY to print the sum of ten numbers. <%= sum %> D. B. <% sum %> B. The request object is an instance of which class? A. A. httpSession D. HttpRequest ServletRequest Request HttpServletRequest 21. C. Now consider the same JSP example as last question. B. C. Select the one correct statement A. JSP pages have access to implicit objects that are exposed automatically. A Java bean with a property color is loaded using the following statement <jsp:usebean id="fruit" class="Fruit"/> What is the effect of the following statement.A. The color attribute is assigned a value "". If there is a non-null request parameter with name color.

Instead of referring the class by its complete package name each time. Select the two correct answers. No. import C. Select the one correct answer. we want to just use ArrayList. contentType generateXML type outputXML 26. Select the two correct statement A. <% page info="test page" %> B. <%@page info="test page" session="false"%> <%@page session="false"%> A. D. This is legal JSP syntax. <%@ page isErrorPage="errorPage. The default value of isThreadSafe attribute of page directive is true. Is the following JSP code legal? Select the one correct statement. Which attribute of page directive may be used to specify that the JSP page is generating an XML file.ArrayList class many times.util. . include D.23. extends B. B. <%@ page session="true" %> D. B. package E. Yes. This code will generate syntax errors. The page directive is used to convey information about the page to JSP container. A.jsp" %> E. A JSP page uses the java. <%@ page info="test page" session="false"%> C. Which of these are true. 25. Which attribute of page directive must be specified to achieve this. A. A JSP page needs to generate an XML file. Which of these are legal syntax of page directive. <%@ page isThreadSafe=true %> 24. classpath 27. A. C.

Select the one correct answer. cannot refer to variables local to the original page. d. page 29. If isThreadSafe attribute of page directive is set to true. pageContext C. A. the JSP container treats the file to be included as if it was part of the original file. So it must not end with a semi colon. Which of these is true about include directive. When using the include directive. When using scriptlets (that is code included within <% %>).B. D. Setting isThreadSage attribute to true for JSP pages. can lead to poor performance. Name the implicit variable available to JSP pages that may be used to access all the other implicit objects. C. servlet F. exclude C. Select the two correct answers. The XML syntax of include directive in <jsp:include file="fileName"/> . A. D. 30. jspPave Answers to questions on JSP 1. B. then JSP container dispatches request for the page sequentially. The included file must have jspf extension. Which of the following are examples of JSP directive. import D. the included code must have legal Java syntax. The content of file included using include directive. include B. context D. page B. 28. taglibrary E. So the first statement must end with a semi-colon. A. object E. a thread is created for each request for the page. The second statement on the other hand is a JSP expression. C. When isThreadSafe attribute of page directive is set to true. .

20. The jsp:setProperty takes three attributes . The following are legal attributes of page directive . But either class or type must be defined. d is incorrect because the value of isErrorPage attribute must be boolean. 7. 17. The option a is incorrect because page directive must be included within <%@ . the value true is not within quotes. errorPage.d. 24. a. The syntax will look like <%@page import="java. then JSP container processes request sequentially. d. jsp:getProperty takes two attributes . a.</jsp:declaration>. a. property and value. e. The if statement. b. b. JSP declarations do not have access to automatically defined variables like request. 25. The scope and class attributes are not required. a. The JSP statement <%!int a. request is an instance of HttpServletRequest 21. Also the jsp:setProperty must end with />. Implicit object session is of type HttpSession. 23. JSP declarations are inserted outside of _jspService method. c. The predefined variables that are available within the JSP expression are session and pageContext. c. session. So these should be included within <% } %> 6.c. Using * for property is legal syntax. After the for loop z and y are both set to 3. 22. B. b.2. The default scope of the declared bean is page.c. The else satement gets evaluated. d. contentType. e. 14. b.name and property. isErrorPage. In this example session attribute is specified twice. The value attribute of setProperty is optional. Hence a is incorrect. 10. language. <jsp:directive. Hence b and d are incorrect. The page directive is defined as <%@page isThreadSafe="false"%> 13. 3.ArrayList"/> 27. There is no such variable as httpsession. 16. b. and this leads to poor performance. c. contentType attribute is used to generate XML. Hence c is incorrect. isThreadSafe. else statement and closing parenthesis are JSP scriptlets and not JSP expressions. As this is a a Java statement it needs to be included with <% and %>. 9. c. and not httpSession and context. 8. 15. info. 18. 11. If isThreadSafe is set to false. e.%> is equivalent to <jsp:declaration>int x. Except the import attribute of page directive. As this is a a Java expression it needs to be included with <%= and %>. all the other attributes of page directive cannot be specified more than once. The name attribute must match the id attribute of jsp:usebean. response etc. extends. The syntax will look like <%@page contentType="text/xml"/> 26.name. 12. The default value of isThreadSafe attribute is true.d. The XML syntax for JSP expression is <jsp:expression>Java expression</jsp:expression> 4. 19. autoFlush. d. a. Hence b is incorrect. and it should not end in semi-colon. This is a legal syntax to set a property of JavaBean. .include> is the XML equivalent of include directive. b. true. c. So a is correct.util. Bean properties are associated with identically named input parameters. and 2 gets printed in the browser. d.import. The XML syntax for JSP scriptlets is <jsp:scriptlet>Java code</jsp:scriptlet> 5. and it needs to end in semi-colon. e is incorrect because.c.

to access other input variables.PageContext.jsp. include. Hence a is incorrect. taglib and page are examples of JSP directives.28. and provides methods like getPage(). a.f. etc. The JSP directives have this syntax <%@directive attribute="value" %> 29.servlet. b. This pageContext object is an instance of type javax. d.include> 30. . getRequest(). The XML syntax of include directive is <jsp:directive. It is not required that the included file has jspf extension.