0

JSP and Servlet Quiz

Description: JSP and Servlet Quiz
Number of Questions: 11
Created by:
Tags: java jsp
Attempted 0/11 Correct 0 Score 0

In JSP, how can you know what HTTP method (GET or POST) is used by client request ?

  1. by using request.getMethod()

  2. by using request.setMethod()

  3. impossible to know

  4. none of these


Correct Option: A
Explanation:

To determine the HTTP method (GET or POST) used by a client request in JSP, you can use the request.getMethod() method.

The correct answer is:

The Answer is: A. by using request.getMethod()

Explanation:

A) by using request.getMethod(): This option is correct. The request.getMethod() method is used to retrieve the HTTP method used by the client request. It returns a string representing the HTTP method, such as "GET" or "POST".

B) by using request.setMethod(): This option is incorrect. The request.setMethod() method does not exist in JSP. There is no built-in method to set the HTTP method of a request.

C) impossible to know: This option is incorrect. It is possible to know the HTTP method used by the client request by using the request.getMethod() method.

D) none of these: This option is incorrect. The correct answer is option A, as explained above.

Therefore, the correct answer is:

The Answer is: A. by using request.getMethod()

What is legal about JSP scriplets

  1. A loop can begin in one Scriptlet and end in another

  2. Statements in Scriptlets should follow Java Syntax

  3. Semicolon is needed at the end of each statement in a Scriptlet

  4. All the above


Correct Option: D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) A loop can begin in one Scriptlet and end in another - This option is incorrect. In JSP, scriptlets are used to embed Java code within the HTML markup. Each scriptlet is treated as a separate block of code and cannot span across multiple scriptlet tags. Therefore, a loop cannot begin in one scriptlet and end in another.

Option B) Statements in Scriptlets should follow Java Syntax - This option is correct. In JSP, scriptlets are used to write Java code. Therefore, any statements written within a scriptlet should follow the syntax rules of the Java programming language.

Option C) Semicolon is needed at the end of each statement in a Scriptlet - This option is correct. In Java, semicolons are used to mark the end of a statement. Similarly, in JSP scriptlets, semicolons are required at the end of each statement to indicate the end of the line of code.

Option D) All the above - This option is correct. Both options B and C are true. Statements in scriptlets should follow Java syntax, and semicolons are needed at the end of each statement in a scriptlet.

Therefore, the correct answer is D) All the above.

Which method is called first each time a Servlet is invoked ?

  1. Start()

  2. Run()

  3. Servive()

  4. init()


Correct Option: D

AI Explanation

To answer this question, you need to understand the lifecycle of a servlet.

When a servlet is first loaded and initialized, the init() method is called. This method is called only once during the entire lifecycle of the servlet. It is used to perform any initialization tasks, such as setting up resources, loading configurations, or establishing database connections.

After the init() method is called, the servlet is ready to handle requests. Each time a request is made to the servlet, the service() method is called. The service() method is responsible for processing the request and generating the response. It determines the HTTP method (GET, POST, etc.) used in the request and calls the appropriate method (doGet(), doPost(), etc.) to handle the request.

The start() and run() methods are not part of the servlet lifecycle. They are methods of the Thread class and are used for multithreading purposes.

Therefore, the correct answer is:

D. init()

Which of the following statement is true ?

  1. Stateless session beans doesn’t preserve any state across method calls

  2. Stateful session beans can be accesses by multiple users at the same time


Correct Option: A
  1. Java applet.

  2. Java servlet.

  3. Either 1 or 2 above.

  4. Neither 1 nor 2 above.


Correct Option: B

What programming language(s) or scripting language(s) does Java Server Pages (JSP) support?

  1. VBScript only

  2. Jscript only

  3. Java only

  4. All of the above are supported


Correct Option: C

AI Explanation

To answer this question, you need to understand what Java Server Pages (JSP) is and the programming languages or scripting languages it supports.

Java Server Pages (JSP) is a technology used for developing web applications. It allows for the dynamic generation of web pages based on Java code. JSP files are HTML files with embedded Java code.

The correct answer is C) Java only. JSP supports only the Java programming language. It allows developers to embed Java code directly into the HTML code of the JSP file. This embedded Java code can be used to generate dynamic content, perform calculations, access databases, and more.

Options A) VBScript only and B) Jscript only are incorrect because JSP does not support these scripting languages. JSP is specifically designed to work with Java.

Option D) All of the above are supported is incorrect because JSP does not support VBScript or Jscript.

Therefore, the correct answer is C) Java only.

  1. Apache Tomcat

  2. Apache Web server

  3. Sun servlet processor

  4. None of the above is correct.


Correct Option: A
  1. A Java application

  2. A Java applet

  3. A Java servlet

  4. None of the above is correct.


Correct Option: C

How many copies of a JSP page can be in memory at a time?

  1. One

  2. Two

  3. Three

  4. Unlimited


Correct Option: A

How does Tomcat execute a JSP?

  1. As a CGI script

  2. As an independent process

  3. By one of Tomcat's threads

  4. None of the above is correct.


Correct Option: C
- Hide questions