Question:* Where in JSP page source can EL functions be used?
Answer: • In the body of a tag where body-content is set to JSP
Question:* Given the following code from a servlet, and given that myvar is a reference to either an HttpSession or a ServletContext: 1. myVar.setAttribute(“myName”, “myVal”); 2. String s = (String) myVar.getAttribute(“myName”); // more code After line 2 executes, which is true?
Answer: • The value of s cannot be guaranteed
Question:* Which of the following is not a valid implicit object in a JSP?
Answer: • context
Question:* Which of the following JSP action can be described as following : Action to substitute the referenced resource's content for the forwarding page's content?
Answer: • jsp:forward
Question:* The correct way to create a cookie is:
Answer: • Cookie cookie = new Cookie("key","value")
Question:* Which of the following methods is most appropriate to send the large amount of data?
Answer: • POST
Question:* JSP's are written in____.
Answer: • Java
Question:* What is the proper Try Catch clause?
Answer: • try { } catch () { }
Question:* The correct way to import the text library in your JSP page is:
Answer: • <%@ page import="java.text.*" %>
Question:* What is the correct way to test if x is equal to 1?
Answer: • if(x == 1) { }
Question:* Data runs between the client and the server via a ___ request.
Answer: • HTTP
Question:* The correct way to import the input/ouput java library is:
Answer: • <%@ page import="java.io.*" %>
Question:* A JSP page ends with____.
Answer: • .jsp
Question:* JavaScript is to the client as JSP is to the ____.
Answer: • the server
Question:* JSP are coded in:
Answer: • Java
Question:* Which one is the correct syntax for JSTL?
Answer: • <%@ taglib prefix="c" uri="http..." %>
Question:* JSP caches data on a web server called___.
Answer: • Tomcat
Question:* The correct syntax for a IF statement in Java is:
Answer: • if () { }
Question:* A Servlet runs on ____
Answer: • the server
Question:* The correct way to create a string in Java is:
Answer: • String var_str = "this";
Question:* The correct way to create a single line comment is:
Answer: • // comment
Question:* Which file is a configuration file for JSP?
Answer: • web.xml
Question:* How are JSP comments written?
Answer: • <%-- comment --%>
Question:* A scriptlet is a piece of code that can be embedded inside the HTML, however it has to be inside which tags?
Answer: • <% java code %>
Question:* The correct way to instantiate a new date object is:
Answer: • Date myDate = new Date();
Question:* If you wanted to print out the html from your program, which would you use?
Answer: • out.println();
Question:* A JSP directive has the following form:
Answer: • <%@ page %>
Question:* Which of the following files contains the mapping for <servlet-name> and <servlet-class>?
Answer: • web.xml
Question:* JSP stands for ____.
Answer: • Java Server Pages
Question:* HTTP is stateless. What does that mean?
Answer: • Once a connection is open then closed, the web server doesn't recognize the request or any past requests.
Question:* a JavaBean is basically a:
Answer: • class
Question:* Service method of a generic servlet takes which of the following parameters?
Answer: • Both ServletRequest & ServletResponse
Question:* Which is the best place to define error pages for JSPs?
Answer: • web.xml
Question:* How does container process a JSP page after compilation?
Answer: • Servlet
Question:* What is the proper taglib for SQL?
Answer: • <sql:update> </sql:update>
Question:* Which of the follolwing servlet methods gets called for each client request?
Answer: • public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException{
Question:* The 3 ways to maintain session between web client and the server are:
Answer: • Cookies, hidden fields, URL rewrite.
Question:* When a web browser asks for a JSP page, the first thing the JSP engine does is:
Answer: • see if the page needs to be compiled
Question:* To deploy and run JavaServer Pages you need...
Answer: • a compatible web server with a servlet container
Question:* Another way to track user data between pages is:
Answer: • session and Cookies
Question:* A container invokes ____ method before taking care of any requests.
Answer: • jspInit()
Question:* Which of the following is an INVALID JSP action?
Answer: • jsp:setSession
Question:* public class SomeServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("a", "value") ; .... } } What would be the scope of a attribute ?
Answer: • Request Scope
Question:* Which of the following is an INVALID bean(object) scope?
Answer: • config
Question:* A JSP comment is ___ in the page code.
Answer: • not included
Question:* If submit a form without mentioning the method type(get or post) and called servlet. which method will invoke? doGet() or doPost().
Answer: • By default it is a GET request
Question:* JSP uses what kind of syntax for an expression?
Answer: • <%= expression %>
Question:* Which of the following are valid sub-elements of taglib?
Answer: • Both taglib-uri and taglib-location
Question:* If a jsp page uses classes from java.util package. Which of the following statements would import the package?
Answer: • <%@ page import="java.util.*"%>
Question:* The JSP container calls the which of the following method if it needs the page to release resources?
Answer: • jspDestroy()
Question:* What is the correct definition for <jsp:useBean>?
Answer: • tries to find an object, creates it if it does not exist
Question:* Which code block is correct?
Answer: • public string myFunc(String name) { return name;}
Question:* Which of the implicit JSP object represents the servlet configuration information?
Answer: • config
Question:* Which of the following object scope is defined as follows : Objects with this scope are accessible from pages processing requests in the same session as the one in which they were created?
Answer: • session
Question:* JSP renders pages vis a ____ Life Cycle.
Answer: • JSP
Question:* Which of the following actions is a specialized tag that generates the appropriate <OBJECT> or <EMBED> tag to load the Java Plug-in software?
Answer: • jsp:plugin
Question:* Which of the following is a Scriplet?
Answer: • <% Java statements %>
Question:* init() or jspInit() is invoked by the container on a servlet or a jsp?
Answer: • Only once in the life time
Question:* What's the difference between servlets and applets? 1.Servlets executes on Servers, where as Applets executes on Browser 2.Servlets have no GUI, where as an Applet has GUI 3. Both of them 4. None of them
Answer: • 3
Question:* What does JSTL stand for?
Answer: • Java Server Pages Standard Library
Question:* If req is a reference to an HttpServletRequest and there is no current session, what is true about req.getSession() ?
Answer: • Invoking req.getSession(true) will return a new session
Question:* Which of the following root element provides the global configuration information for the JSP files in a Web application?
Answer: • jsp-config
Question:* Which of the following is a valid JSP expression?
Answer: • <%= some-java-expression %>
Question:* Which of the following provides a handle to access page directive attributes in the scripting environment?
Answer: • pageContext
Question:* Once the JSP has been requested and the page is loaded and initialized, the JSP engine calls the:
Answer: • _jspService() method
Question:* The Web container creates JSP implicit objects like...
Answer: • pageContext, servletContext, session, request & response
Question:* When might a JSP get translated (Choose all that apply)? a. When the application is started b. When the developer compiles code in the src folder c. The first time a user requests the JSP d. After jspdestroy() is called, it gets retranslated
Answer: • a and c
Question:* Which of the following methods is abstract in HttpServlet?
Answer: • It has no abstract methods
Question:* Which types can be used in conjunction with HttpServletResponse methods to stream output data?
Answer: • java.io.PrintWriter
Question:* Objects which when compiled down are contained in (a) ____ file.
Answer: • jar
Question:* Which of the following is not a 'page' directive attribute?
Answer: • implements
Question:* How can you call a servlet to autofill a dropdown list which depends on selection from previous 2 dropdown lists? 1. Print all possible values of the 2nd and 3rd dropdown out as a Javascript object 2. Make use of XMLHttpRequest in Javascript to fire an asynchronous request to a servlet during the onchange event 3. Both of them 4. None of them
Answer: • 3
Question:* Which of the following classes has an implementation of getSession method that returns an HttpSession object?
Answer: • HttpServletRequest
Question:* Which of the following is not a valid standard method called as part of the JSP life cycle by the container?
Answer: • jspService
Question:* Which of the following statement correctly describe attribute 'buffer'?
Answer: • It indicates whether the content output from the page will be buffered
Question:* Which statements are true: a. The element (subelement of ) set to “false” forces the container to make the servlet unreachable for request to the defined url-pattern, b. The element (subelement of ) set to “false” forces the container to make the request for the servlet respond with HTTP Code 503 (Service unavailable), c. The web fragment is merged into the final Deployment Descriptor after the web fragment related annotations are processed, d. All web fragments are processed together (in a batch) and all are merged into the final Deployment Descriptor before the web fragments’ related annotations are processed.
Answer: • a only
Question:* When using HTML forms which of the folowing is true for POST method?
Answer: • POST method sends data in the body of the request
Question:* Which of the following methods can be used to get initialization and startup parameters of a servlet?
Answer: • getServletConfig
Question:* Which of the following is an INVALID implicit EL objects?
Answer: • session
Question:* What results from a call to the getInitParameterNames() method on ServletContext when there are no context parameters set up in the deployment descriptor?
Answer: • An empty Enumeration object is returned
Question:* Which one is not a part of the JSTL library group?
Answer: • HTML
Question:* Considering the following Servlet code, choose the statement which is true: package com.nullhaus; import javax.servlet.annotation.*; import javax.servlet.http.*; @WebServlet("nullHausServlet") public class NullServlet extends HttpServlet { }
Answer: • This is an invalid usage of @WebServlet annotations because of the wrongly formed url-pattern value
Question:* JSP implicit object 'out' is an object of which of the following classes?
Answer: • JspWriter
Question:* Which methods are needed to get the complete and exact URL that causes the call to arrive at the servlet? 1. getRequestURL() 2. getQueryString() 3. Both of them 4. None of them
Answer: • 3
Question:* Given: 1. <%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %> 2. <%@ taglib prefix = “tables” uri= http://www.javaranch.com/tables %> 3. <%@ taglib prefix = “jsp” tagdir=”/WEB_INF/tags” %> 4. <%@ taglib uri=”UtilityFunctions” prefix=”util” %> What about the above taglib directives would cause the JSP to not function?
Answer: • Line 4 is wrong because the uri value must begin with http://
Question:* By default, the servlet API uses a ______ to store a session ID.
Answer: • cookie
Question:* Which from the following client redirect options are valid?
Answer: • <c:redirect url="http://www.photofuntoos.com"/>
Question:* Which of the following method is called before the page service any requests?
Answer: • jspInit()
Question:* Which of the following is not a valid java bean (POJO) scope in JSP?
Answer: • response
Question:* JSP implicit object 'application' is an object of which of the following class?
Answer: • javax.servlet.ServletContext
Question:* A programmer needs to update a live, running servlet’s initialization parameters so that the web application will begin to use the new parameters immediately. In order to accomplish this, which must be true (although not necessarily sufficient)? 1. The container must destroy and then reinitialize the servlet 2. The servlet’s constructor must retrieve the updated DD parameter from the servlet’s ServletConfig object 3. For each parameter, the DD must have a separate <init-param> tag 4. For each parameter, you must modify a DD tag that specifies the name of the servlet, the name of the parameters, and the new value of the parameter.
Answer: • 1 and 3
Question:* The http GET, PUT, and DELETE verbs are idempotent. What does the term "idempotent" stand for?
Answer: • The same operation applied multiple times yields the same result
Question:* JSP implicit object 'exception' is an object of which of the following classes?
Answer: • java.lang.Throwable
Question:* Which of the following object scope is defined as follows : Objects with this scope are accessible from pages processing requests in the same application as the one in which they were created?
Answer: • application
Question:* Which of the following is valid about 'page' JSP directive?
Answer: • Controls properties of the JSP
Question:* Which of the following HTTP method sends the same response as request?
Answer: • TRACE
Question:* Given a servlet containing the following code, what is the outcome of attempting to compile and run the servlet? ServletContext context = getServletContext(); String s = context.getAttribute("javax.servlet.context.tempdir");
Answer: • The servlet won’t compile
Question:* Why do you get this error? NoClassDefFoundError: org.apache.commons.lang.StringUtils. 1. The given class could not be found. 2. The given class could be found, but something went wrong when initializing it 3. None of them
Answer: • 2
Question:* What is the limit of data to be passed from HTML when doGet() method is used?
Answer: • 2k
Question:* Which of the following is a non-idempotent HTTP method
Answer: • POST
Question:* How can you make the JSP class implement the SingleThreadModel interface?
Answer: • <%@ page isThreadSafe="false" %>
Question:* javax.servlet.jsp.JspPage extends which of the following interfaces?
Answer: • Servlet
Question:* What is true about the life cycle of a servlet?
Answer: • Each time doPost() is invoked, it runs in its own thread
Question:* Which of the following is an INVALID attribute for tag directive?
Answer: • tag-attributes
Question:* When comparing servlet initialisation parameters to context intialisation parameters, which is true among the following?
Answer: • In their respective DD tags, they both have a <param-name> and a <param-value> tag
Question:* <jsp:include page="/servlet/MyServlet" flush="true"/>
Answer: • Invoke a Servlet from a JSP page.
Question:* What is the likely outcome from running the code below? protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher dispatcher = getServletContext().getNamedDispatcher("/ServletB"); dispatcher.forward(request, response); }
Answer: • NullPointerException
No comments:
Post a Comment