Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IBM Servlet and JSP question

 
Joe Nguyen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks
Would you give me some inputs to answer the following IBM questions?
When comparing servlets and JSPs, which of the following are true?
a) JSPs provide better performance than servlets.

b) JSPs may call servlets and servlets may also call JSPs.

c) A JSP must be compiled into a servlet before it can be used.

d) Initialization and destruction behavior is supported in both servlets and JSPs.

(pick 2 answers)
I pick b and c. But I doubt that both servlets and jsp support initialization and destruction as well. Actually, one of the threads indicates both servlet and jsp have init and destroy. If it is true, please let me know why b or c is an incorrect answer.

Implementing the SingleThreadModel interface :
a) requires all servlet methods be declared as synchronized.

b) guarantees that synchronization problems will never occur.

c) may have a negative impact on performance.

d) prevents multiple HTTP request threads from accessing a single servlet instance concurrently.

Multiple Select - Please select all of the correct answers (this question has 2 correct choices).

I pick c and d. However, I think b is also a correct answer since there is at most one thread being executed at a time. One reason I don't pick b because
if thread 1 executes and suppends. Thread 2 now can execute and wait for a resource that has been held by thread 1. Then synchronized problem may occur. Please, correct me if my rationale is incorrect.
Thanks in advance
 
scott irwin
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joey,
1) If I have to pick 2, then I pick c and d. C - All JSP files get compiled into servlets and then are used. D - JSP does support jspInit() and jspDestroy() (JSP 1.1 Section 3.2.1). As far as B goes, the term "call" doesn't fit. A JSP can "include" and "forward" another JSP/Servlet. If you said pick three, I would have included B.
2) B is not correct. The only thing the JSP/Servlet container guarantees is that no two threads will execute your code at a given time. However, N threads can access the same objects in the session or application scope and static members.
Scott
[This message has been edited by scott irwin (edited May 16, 2001).]
 
Joe Nguyen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Scott
Thanks for verifying the second answer. For the first answer, I think servlet can call jsp and vice versa meaning that servlet can transfer the control to jsp and vice versa.
joey
 
scott irwin
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joey,
True. But you said pick 2. So c and d are correct as is. You can "include" which basically in-lines the result of other jsp/servlet or "forward" which completes the control of this jsp/servlet and passes it to the next jsp/servlet. But you can not "call" another jsp/servlet. This is semantics. I would agree that had you said "pick 3", I would have defined "call" to mean "forward" and "include".
Scott
 
Danl Thompson
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the first one, technically, C is incorrect. You do not have to compile a JSP page before it can be used. The JSP page is compiled by the system the first time it is called. It's a nasty question. B and D are the right answers.
dan'l
 
scott irwin
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A nasty question for sure. Technically C is correct I believe because it doesn't state who compiles the JSP file. It simply states in fact that it must be compiled. If the wording was "...compiled by the developer into...", I would agree.
Scott
 
Danl Thompson
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I went through the IBM mock test back in January in a very methodical way. I answered every question wrong so that I got a zero score, and then went back and poked at any tough questions until I got just that one question right. And while I couldn't believe that C was really incorrect, that's the way it scores on this question. So it has to be a matter of sematics.
Some people call me obsessive.
dan'l
 
scott irwin
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't trust what IBM says as far as I can throw a stack of red books! But that's a whole other thread.
Scott
 
d apple
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason C is incorrect is because JSPs don't have to be compiled into a servlet. Now, they must be compiled before use, but the Servlet spec doesn't require that it be into a class that extends javax.servelt.Servlet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic