Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
What happens first when a JSP page is requested and has not yet been compiled?
Not quite. Try another option.
Answer: The JSP is translated into a servlet
The JSP container first translates the JSP page into servlet source code.
Question 2 of 60 · Lifecycle of a JSP page · Easy
Which JSP lifecycle method is normally called only once after the servlet instance is created?
Not quite. Try another option.
Answer: jspInit()
jspInit() initializes the JSP servlet and is normally called once during its lifecycle.
Question 3 of 60 · Lifecycle of a JSP page · Easy
Which method processes each client request for a JSP page?
Not quite. Try another option.
Answer: _jspService()
The JSP container calls _jspService() for every request to the JSP page.
Question 4 of 60 · Lifecycle of a JSP page · Easy
Which method is called before a JSP servlet is removed from service?
Not quite. Try another option.
Answer: jspDestroy()
jspDestroy() allows the JSP servlet to release resources before it is removed.
Question 5 of 60 · Directory structure of JSP · Easy
Which directory commonly stores compiled Java classes in a Java web application?
Not quite. Try another option.
Answer: WEB-INF/classes
WEB-INF/classes stores compiled application classes and related classpath resources.
Question 6 of 60 · Directory structure of JSP · Easy
Which directory commonly stores JAR library files for a JSP web application?
Not quite. Try another option.
Answer: WEB-INF/lib
WEB-INF/lib contains JAR files required by the web application.
Question 7 of 60 · Directory structure of JSP · Easy
What is generally true about a JSP file placed inside the WEB-INF directory?
Not quite. Try another option.
Answer: It cannot be requested directly by a browser
Resources inside WEB-INF are protected from direct browser access but can be reached through server-side forwarding.
Question 8 of 60 · JSP API · Easy
Which package traditionally contains the core JSP API classes and interfaces?
Not quite. Try another option.
Answer: javax.servlet.jsp
The traditional JSP API is provided primarily through the javax.servlet.jsp package.
Question 9 of 60 · JSP API · Easy
Which JSP API class provides access to page-related attributes and servlet objects?
Not quite. Try another option.
Answer: PageContext
PageContext provides access to attributes, scopes, and several JSP-related objects.
Question 10 of 60 · Scriptlet tag · Easy
Which syntax represents a JSP scriptlet tag?
Not quite. Try another option.
Answer: <% Java code %>
A scriptlet uses <% ... %> to place Java statements inside a JSP page.
Question 11 of 60 · Scriptlet tag · Easy
What can be written inside a JSP scriptlet?
Not quite. Try another option.
Answer: Java statements
Scriptlets contain Java statements that execute while the request is being processed.
Question 12 of 60 · Expression tag · Easy
Which syntax is used for a JSP expression?
Not quite. Try another option.
Answer: <%= value %>
A JSP expression uses <%= ... %> and writes the evaluated value to the response.
Question 13 of 60 · Expression tag · Easy
What is the main purpose of a JSP expression tag?
Not quite. Try another option.
Answer: To display an evaluated value
The result of a JSP expression is converted to text and included in the response.
Question 14 of 60 · Declaration tag · Easy
Which syntax represents a JSP declaration tag?
Not quite. Try another option.
Answer: <%! declaration %>
A JSP declaration uses <%! ... %> to declare fields or methods in the generated servlet.
Question 15 of 60 · Declaration tag · Easy
What is commonly declared using a JSP declaration tag?
Not quite. Try another option.
Answer: Fields and methods
Declaration tags define fields and methods as members of the generated servlet class.
Question 16 of 60 · JSP implicit objects · Easy
Which JSP implicit object represents the client's HTTP request?
Not quite. Try another option.
Answer: request
The request object contains request parameters, headers, attributes, and other client request data.
Question 17 of 60 · JSP implicit objects · Easy
Which JSP implicit object is used to write content to the response?
Not quite. Try another option.
Answer: out
The out object is a JspWriter used to send text content to the client.
Question 18 of 60 · JSP implicit objects · Easy
Which JSP implicit object stores data associated with a user's session?
Not quite. Try another option.
Answer: session
The session object stores user-specific data across multiple requests.
Question 19 of 60 · JSP action tags · Easy
Which JSP action tag includes another resource while processing the current request?
Not quite. Try another option.
Answer: <jsp:include>
<jsp:include> includes the output of another resource in the current response.
Question 20 of 60 · JSP action tags · Easy
Which JSP action tag transfers request processing to another resource?
Not quite. Try another option.
Answer: <jsp:forward>
<jsp:forward> forwards the current request and response to another server-side resource.
Question 21 of 60 · Lifecycle of a JSP page · Medium
A JSP page is requested for the first time after deployment. Which sequence best represents the major lifecycle stages performed by the container?
Not quite. Try another option.
Answer: Translate JSP, compile servlet, initialize it, service the request
The container translates the JSP into servlet source, compiles it, loads and initializes the servlet, and then services the request.
Question 22 of 60 · Lifecycle of a JSP page · Medium
A JSP needs to open a database connection pool once when its generated servlet is initialized and release it before the servlet is removed. Which methods are most appropriate?
Not quite. Try another option.
Answer: Open it in jspInit() and release it in jspDestroy()
jspInit() performs one-time initialization, while jspDestroy() releases resources when the generated servlet is taken out of service.
Question 23 of 60 · Lifecycle of a JSP page · Medium
A JSP file is modified after it has already handled several requests. What will a typical JSP container do on the next request?
Not quite. Try another option.
Answer: Retranslate and recompile the JSP before serving it
Containers normally detect that the JSP source is newer than its generated servlet and perform translation and compilation again.
Question 24 of 60 · Directory structure of JSP · Medium
A JSP imports the class com.example.Cart, which is not packaged in a JAR. Where should Cart.class be placed in the web application?
Not quite. Try another option.
Answer: WEB-INF/classes/com/example/Cart.class
Unpacked application classes belong under WEB-INF/classes, following their Java package directory structure.
Question 25 of 60 · Directory structure of JSP · Medium
A developer wants reports.jsp to be accessible only through a server-side forward, not by entering its URL directly. Which location is most suitable?
Not quite. Try another option.
Answer: WEB-INF/views/reports.jsp
Resources inside WEB-INF cannot be requested directly by clients, but the server can access them through forwarding or inclusion.
Question 26 of 60 · JSP API · Medium
A JSP writes a large amount of generated text using the implicit out object. What is the declared JSP API type of this object?
Not quite. Try another option.
Answer: javax.servlet.jsp.JspWriter
The JSP out object is a JspWriter, which supports buffered character output for the JSP response.
Question 27 of 60 · JSP API · Medium
The same attribute name exists in page, request, session, and application scopes. Which value is returned by pageContext.findAttribute("status")?
Not quite. Try another option.
Answer: The value stored in page scope
findAttribute() searches scopes in the order page, request, session, and application, returning the first match.
Question 28 of 60 · JSP API · Medium
Which statement correctly describes the _jspService() method defined by the JSP servlet model?
Not quite. Try another option.
Answer: The container invokes it for each request to the JSP
The generated servlet's _jspService() method processes requests. JSP authors should not declare or override this method directly.
Question 29 of 60 · Scriptlet tag · Medium
Which JSP fragment correctly uses a scriptlet to display Adult only when the request parameter age represents a value of at least 18?
Not quite. Try another option.
Answer: <% if (Integer.parseInt(request.getParameter("age")) >= 18) { %>Adult<% } %>
A scriptlet uses <% ... %> and can contain Java control-flow statements whose blocks surround template text.
Question 30 of 60 · Scriptlet tag · Medium
Consider the fragment <% int total = 0; total++; %>. Where is total normally declared in the generated servlet?
Not quite. Try another option.
Answer: As a local variable inside _jspService()
Code in a scriptlet is inserted into _jspService(), so variables declared there are normally local to the current request-processing invocation.
Question 31 of 60 · Expression tag · Medium
Which scriptlet is functionally equivalent to the JSP expression <%= product.getPrice() %>?
Not quite. Try another option.
Answer: <% out.print(product.getPrice()); %>
A JSP expression evaluates its expression and writes the resulting value to the response through out.
Question 32 of 60 · Expression tag · Medium
A page contains <%= request.getParameter("name").toUpperCase() %>. What happens if the request has no name parameter?
Not quite. Try another option.
Answer: A NullPointerException occurs during request processing
getParameter("name") returns null when the parameter is absent, and calling toUpperCase() on null causes a NullPointerException.
Question 33 of 60 · Declaration tag · Medium
A JSP must define a helper method named formatName that can be called from multiple expressions in the page. Which syntax declares it as a generated servlet member?
The declaration tag <%! ... %> places fields and methods at class level in the generated servlet.
Question 34 of 60 · Declaration tag · Medium
A JSP contains <%! int visits = 0; %> followed by <%= ++visits %>. Why can the displayed count be unreliable under concurrent requests?
Not quite. Try another option.
Answer: visits is a shared servlet field updated without synchronization
A declaration creates an instance field in the generated servlet. Multiple request threads can update that shared field concurrently.
Question 35 of 60 · JSP implicit objects · Medium
A custom error page needs to display the exception that caused request processing to fail. Which configuration makes the implicit exception object available?
Not quite. Try another option.
Answer: Set <%@ page isErrorPage="true" %> on the error page
The exception implicit object is available only on a JSP declared as an error page with isErrorPage="true".
Question 36 of 60 · JSP implicit objects · Medium
A JSP declares <%@ page session="false" %>. Which implicit object is unavailable to that page?
Not quite. Try another option.
Answer: session
Setting session="false" prevents the JSP from participating in an HTTP session and removes the session implicit object.
Question 37 of 60 · JSP implicit objects · Medium
A value must be shared by all users and all JSP pages within the same deployed web application. Which implicit object should store it?
Not quite. Try another option.
Answer: application
The application object represents the ServletContext, whose attributes are shared across the entire web application.
Question 38 of 60 · JSP action tags · Medium
A JSP must include the current output of menu.jsp every time the page is requested. Which standard action is most appropriate?
Not quite. Try another option.
Answer: <jsp:include page="menu.jsp" />
jsp:include performs a request-time inclusion, so the included resource is executed and its current output is inserted.
Question 39 of 60 · JSP action tags · Medium
A JSP has already flushed its response buffer and then executes <jsp:forward page="login.jsp" />. What is the most likely result?
Not quite. Try another option.
Answer: An IllegalStateException occurs because the response is committed
A server-side forward requires an uncommitted response. Once the buffer has been flushed, the response normally cannot be replaced.
Question 40 of 60 · JSP action tags · Medium
Consider <jsp:useBean id="cart" class="shop.Cart" scope="session" />. What happens when the session already contains an attribute named cart of the expected type?
Not quite. Try another option.
Answer: The existing session bean is reused
jsp:useBean searches the specified scope for the named bean and creates a new instance only when a suitable bean is not already present.
Question 41 of 60 · Lifecycle of a JSP page · Hard
For the first successful request to a newly deployed JSP that has not been precompiled, which lifecycle sequence is correct?
Not quite. Try another option.
Answer: Translate JSP, compile servlet, load and instantiate it, call jspInit(), then call _jspService()
The container translates the JSP into servlet source, compiles and loads it, creates an instance, calls jspInit() once, and invokes _jspService() for each request.
Question 42 of 60 · Lifecycle of a JSP page · Hard
A JSP contains the declaration <%! public void _jspService(HttpServletRequest r, HttpServletResponse s) { } %>. What is the expected result?
Not quite. Try another option.
Answer: The page fails translation or compilation because _jspService() is container-generated
A JSP author may define jspInit() and jspDestroy(), but must not define _jspService(). The container generates that method from the JSP template and scripting elements.
Question 43 of 60 · Directory structure of JSP · Hard
A JSP is deployed as /WEB-INF/reports/summary.jsp. Which statement about accessing it is correct?
Not quite. Try another option.
Answer: It is protected from direct requests but reachable through a request dispatcher
Resources under WEB-INF cannot be requested directly by clients, but server-side components can reach them using forwarding or inclusion.
Question 44 of 60 · Directory structure of JSP · Hard
A loose compiled class has the binary name com.acme.Report and must be visible to JSP pages in a standard WAR. Where should it be placed?
Not quite. Try another option.
Answer: WEB-INF/classes/com/acme/Report.class
Loose application classes belong under WEB-INF/classes, preserving their package directory structure. JAR dependencies instead belong under WEB-INF/lib.
Question 45 of 60 · JSP API · Hard
Which statement correctly describes the relationship among the core JSP page interfaces?
Not quite. Try another option.
Answer: HttpJspPage extends JspPage and declares _jspService() for HTTP requests
JspPage extends Servlet and defines jspInit() and jspDestroy(). HttpJspPage extends it and adds _jspService(HttpServletRequest, HttpServletResponse).
Question 46 of 60 · JSP API · Hard
A buffered JspWriter has already flushed some content to the client. Which distinction between clear() and clearBuffer() is correct?
Not quite. Try another option.
Answer: clear() can fail after a flush, while clearBuffer() cannot retract content already emitted
clear() throws an IOException if the buffer has already been flushed. clearBuffer() clears current buffered content but cannot undo bytes already sent.
Question 47 of 60 · Scriptlet tag · Hard
Assuming no surrounding whitespace, what is produced by <% for (int i = 0; i < 2; i++) { %><%= i %><% } %>?
Not quite. Try another option.
Answer: 01, because the Java loop spans the separated JSP scripting elements
Scriptlets and expressions are combined into the generated _jspService() method. The opening and closing braces therefore form one valid Java loop around the expression.
Question 48 of 60 · Scriptlet tag · Hard
What happens when a JSP contains <% int calculate() { return 42; } %> inside a scriptlet?
Not quite. Try another option.
Answer: Compilation fails because Java does not allow method declarations inside a method
Scriptlet code is inserted inside _jspService(). A method cannot be declared inside another Java method; a JSP declaration tag would be required.
Question 49 of 60 · Expression tag · Hard
What is the result of placing <%= response.flushBuffer() %> in a JSP?
Not quite. Try another option.
Answer: Compilation fails because the expression has the type void
A JSP expression is translated approximately to out.print(expression). Since flushBuffer() returns void, it cannot be passed as a value to print().
Question 50 of 60 · Declaration tag · Hard
Why does <%! String user = request.getParameter("u"); %> normally fail to compile?
Not quite. Try another option.
Answer: request is local to _jspService() and is unavailable in member scope
A declaration creates a class member. Request-specific implicit objects are local variables established inside _jspService(), so they cannot be referenced by member initializers.
Question 51 of 60 · Declaration tag · Hard
A JSP declares <%! int hits = 0; %> and executes <% hits++; %> for every request. Under the usual servlet threading model, which statement is correct?
Not quite. Try another option.
Answer: The field is shared by concurrent requests, and hits++ can lose updates
A declaration creates an instance field of the JSP servlet. Multiple request threads commonly use the same instance, and hits++ is not an atomic operation.
Question 52 of 60 · JSP implicit objects · Hard
The attribute key exists in all four standard scopes with different values. What does pageContext.findAttribute("key") return?
Not quite. Try another option.
Answer: The page-scope value, because lookup order is page, request, session, application
findAttribute() searches scopes in the fixed order page, request, session, and application, returning the first matching value.
Question 53 of 60 · JSP implicit objects · Hard
A source JSP specifies <%@ page errorPage="failure.jsp" %>. Under what condition can failure.jsp directly use the implicit object exception?
Not quite. Try another option.
Answer: It must declare <%@ page isErrorPage="true" %>
The exception implicit object is available only in a JSP marked as an error page using isErrorPage="true".
Question 54 of 60 · JSP implicit objects · Hard
A JSP begins with <%@ page session="false" %> and later contains <%= session.getId() %>. What is the expected outcome?
Not quite. Try another option.
Answer: Translation or compilation fails because session is unavailable
Setting session="false" prevents the JSP from participating in sessions and removes the session implicit object from the page.
Question 55 of 60 · JSP action tags · Hard
A parent JSP was translated yesterday. Today, fragment.jsp is modified, but the parent is not retranslated. Which mechanism is designed to use the fragment's current request-time output?
Not quite. Try another option.
Answer: <jsp:include page="fragment.jsp" /> because inclusion occurs during request processing
jsp:include dynamically invokes the target for each request. The include directive merges source during translation and may require parent retranslating to reflect changes.
Question 56 of 60 · JSP action tags · Hard
A JSP writes content into an uncommitted response buffer and then executes <jsp:forward page="target.jsp" />. What should occur?
Not quite. Try another option.
Answer: The uncommitted buffer is cleared, and the target produces the forwarded response
A forward clears uncommitted buffered output before transferring control. If the response has already been committed, forwarding instead throws IllegalStateException.
Question 57 of 60 · JSP action tags · Hard
A request-scope bean named c already exists with count = 9. What happens here: <jsp:useBean id="c" class="com.acme.Counter" scope="request"><jsp:setProperty name="c" property="count" value="1" /></jsp:useBean>?
Not quite. Try another option.
Answer: The existing bean is reused, and its count remains 9
The body of jsp:useBean executes only when the action creates a new bean. If a compatible scoped bean already exists, the body is skipped.
Question 58 of 60 · JSP action tags · Hard
No attribute named items exists in request scope. What happens with <jsp:useBean id="items" type="java.util.List" scope="request" />?
Not quite. Try another option.
Answer: An InstantiationException occurs because no creation class was supplied
The type attribute can type-check an existing object but does not identify a concrete class to instantiate. With no existing bean and no class or beanName, creation fails.
Question 59 of 60 · JSP action tags · Hard
A bean initially has name = "Mira", age = 4, and active = true. The request parameters are age=12 and extra=x. After <jsp:setProperty name="person" property="*" />, what state is expected?
Not quite. Try another option.
Answer: name = "Mira", age = 12, and active = true
With property="*", matching request parameters update corresponding bean properties. Missing properties remain unchanged, and unmatched parameters such as extra are ignored.
Question 60 of 60 · JSP action tags · Hard
The original request contains mode=old, and a JSP performs <jsp:include page="target.jsp"><jsp:param name="mode" value="new" /></jsp:include>. What does request.getParameter("mode") return inside target.jsp?
Not quite. Try another option.
Answer: new, because the action parameter takes precedence in the included resource
Parameters supplied through jsp:param are added for the dispatched resource and take precedence over existing values with the same name.
That's unit 4
Answer a few questions and your score shows up here.
Nearly through. Did unit 4 of CSE406 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 4 of CSE406 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.