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

Compilation Error or Translation Error?

 
Hema Nandhini
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is from SCWCD Study Companion by Charles Lyons. Page no: 260 Question no: 5


Answer is : E

Explanation: There is no import for the java.util.Date. So compilation error occurs.

But will this not cause translation error? Because during translation, the container checks for syntax and if the accessed elements are available to the JSP.
[ August 11, 2008: Message edited by: Hema Nandhini ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The container will output the expression "as is" in the translated java servlet. It is not smart enough, and it is not his role during the translation phase, to check for missing imports or bad syntax in scriptlets or expressions. On the other hand, the compiler will find this type of errors.

In this example, the jsp file will be successfully translated, and you'll find something like "out.print( new Date() );" in the translated java servlet. But when the servlet is compiled, the Date class will not be found, generating a compilation-time exception.
 
Hema Nandhini
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Verre.. So in general what type of errors will be caught during translation?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The container validates the syntactic correctness of the JSP pages and tag files. For example, JSP related syntax will be checked. If you have something like :

The container will not recognize it, resulting in a translation error.
 
Ramesh Ponnada
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%= new Date() %>

This jsp can be included in another jsp page in which java.util.Date is imported, which is perfectly valid.

So I think this is one of the reasons why translation just do as is copy of statements into servlet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic