JSP and Servlet Quiz
Description: JSP and Servlet Quiz | |
Number of Questions: 11 | |
Created by: Aliensbrain Bot | |
Tags: java jsp |
In JSP, how can you know what HTTP method (GET or POST) is used by client request ?
-
by using request.getMethod()
-
by using request.setMethod()
-
impossible to know
-
none of these
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
-
A loop can begin in one Scriptlet and end in another
-
Statements in Scriptlets should follow Java Syntax
-
Semicolon is needed at the end of each statement in a Scriptlet
-
All the above
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 ?
-
Start()
-
Run()
-
Servive()
-
init()
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 ?
-
Stateless session beans doesn’t preserve any state across method calls
-
Stateful session beans can be accesses by multiple users at the same time
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?
-
A Java application
-
A Java applet
-
A Java servlet
-
None of the above is correct.
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):
-
Java applet.
-
Java servlet.
-
Either 1 or 2 above.
-
Neither 1 nor 2 above.
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?
-
VBScript only
-
Jscript only
-
Java only
-
All of the above are supported
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.
What servlet processor was developed by Apache Foundation and Sun?
-
Apache Tomcat
-
Apache Web server
-
Sun servlet processor
-
None of the above is correct.
AI Explanation
To answer this question, you need to understand the concept of servlet processors and the technologies developed by Apache Foundation and Sun.
Option A) Apache Tomcat - This option is correct. Apache Tomcat is a servlet container developed by the Apache Foundation in collaboration with Sun Microsystems. It is an open-source software implementation of the Java Servlet, JavaServer Pages (JSP), and WebSocket technologies.
Option B) Apache Web server - This option is incorrect. Apache Web server, also known as Apache HTTP Server, is a web server software developed by the Apache Software Foundation. While it can be used to serve static web pages, it is not specifically designed as a servlet processor.
Option C) Sun servlet processor - This option is incorrect. While Sun Microsystems, now Oracle Corporation, has contributed to the development of Java technologies, there is no specific servlet processor named "Sun servlet processor."
Option D) None of the above is correct - This option is incorrect. The correct answer is Apache Tomcat, which is the servlet processor developed by the Apache Foundation and Sun Microsystems.
The correct answer is A) Apache Tomcat. This option is correct because Apache Tomcat is the servlet processor developed by the Apache Foundation and Sun Microsystems.
What is invoked via HTTP on the Web server computer when it responds to requests from a user's Web browser?
-
A Java application
-
A Java applet
-
A Java servlet
-
None of the above is correct.
How many copies of a JSP page can be in memory at a time?
-
One
-
Two
-
Three
-
Unlimited
How does Tomcat execute a JSP?
-
As a CGI script
-
As an independent process
-
By one of Tomcat's threads
-
None of the above is correct.