JSP execution model basics At runtime, a JavaServer Page (JSP) is first transformed by the container into which executable server-side artifact?
-
AJava applet.
-
BJava servlet.
-
CEither 1 or 2 above.
-
DNeither 1 nor 2 above.
-
EA native binary module.
Answer
Correct Answer: Java servlet.
Explanation
Introduction / Context:JSP (JavaServer Pages) provides a templating model where HTML (or other markup) is interleaved with server-side Java elements. Understanding the lifecycle clarifies deployment, performance, and debugging behavior in Java web applications.
Given Data / Assumptions:
- A JSP is deployed to a Java EE/Servlet container (for example, Tomcat).
- The container manages compilation and execution.
- No browser plugins (like applets) are involved in server execution.
Concept / Approach:
When a JSP is requested, the container translates the JSP into a Java source file that extends the servlet base classes. It then compiles this source into bytecode and loads it as a servlet. Subsequent requests run the compiled servlet class until the JSP is changed, at which point the container recompiles as needed. Thus, at runtime a JSP becomes a servlet, not an applet.
Step-by-Step Solution:
JSP received → translate to Java servlet source.Compile source to servlet bytecode (a .class).Load and execute the servlet to generate dynamic content.On JSP updates, retranslate/recompile automatically.Verification / Alternative check:
Servlet container documentation describes JSP translation-phases and servlet lifecycle; IDE tools can show the generated servlet code for debugging.
Why Other Options Are Wrong:
- A: Applets run in a browser JVM; JSPs run on the server.
- C/D/E: Do not reflect the standard JSP compilation model.
Common Pitfalls:
- Assuming JSPs execute as scripts; they execute as compiled servlets.
- Editing generated servlet code—changes are overwritten; edit the JSP itself.
Final Answer:
Java servlet.