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()

  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

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

What is sent to the user via HTTP, invoked using the HTTP protocol on the user's computer, and run on the user's computer as an application?

  1. A Java application

  2. A Java applet

  3. A Java servlet

  4. None of the above is correct.


Correct Option: B

AI Explanation

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

Option A) A Java application - This option is incorrect because a Java application is typically executed on a server and not sent to the user's computer via HTTP.

Option B) A Java applet - This option is correct because a Java applet is sent to the user's computer via HTTP, invoked using the HTTP protocol, and run on the user's computer as an application.

Option C) A Java servlet - This option is incorrect because a Java servlet is executed on a server and not sent to the user's computer via HTTP.

Option D) None of the above is correct - This option is incorrect because option B, a Java applet, is the correct answer.

The correct answer is B) A Java applet. This option is correct because it is sent to the user via HTTP, invoked using the HTTP protocol on the user's computer, and run on the user's computer as an application.

A JSP is transformed into a(n):

  1. Java applet.

  2. Java servlet.

  3. Either 1 or 2 above.

  4. Neither 1 nor 2 above.


Correct Option: B

AI Explanation

To answer this question, you need to understand the role of JSP (JavaServer Pages) and its transformation process.

JSP is a technology used to create dynamic web pages. It allows developers to embed Java code within HTML pages, which is then executed on the server side. JSP pages are transformed into Java servlets during the compilation process.

Option A) Java applet - This option is incorrect because JSP pages are not transformed into Java applets. Java applets are client-side programs that run within a web browser and are embedded within HTML pages.

Option B) Java servlet - This option is correct. JSP pages are transformed into Java servlets. Servlets are server-side programs that run on a web server and generate dynamic content to be sent back to the client.

Option C) Either 1 or 2 above - This option is incorrect because JSP pages are specifically transformed into Java servlets and not Java applets.

Option D) Neither 1 nor 2 above - This option is incorrect. JSP pages are transformed into Java servlets, so option D is not the correct answer.

The correct answer is B) Java servlet. This option is correct because JSP pages are transformed into Java servlets during the compilation process.

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

What is invoked via HTTP on the Web server computer when it responds to requests from a user's Web browser?

  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