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

Regarding jsp comment

 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will be the result of this jsp line if the user takes a look at the page source code?
<!-- Today is <%= new java.util.Date() %>.Hava a nice day -->

1) It won't compile
2) The user won't see the comment
3) The user will see the same jsp line as above
4) The user will see the comment with the current date because the expression is evaluated at runtime.

Answer given is

4) The user will see the comment with the current date because the expression is evaluated at runtime.

This example is in the JSP especifications.


But I thought comments will be ignored when jsp is converted to a servlet.Then how will the scriptlet get executed?
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because that comment is an XML comment.
The specs refer to scriptlet comments, like
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But still container will ignore jsp comments when they convert it to a Servlet,then how will the scriptlet gets executed?
 
PRavi kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<!-- Today is <%= new java.util.Date() %>.Hava a nice day --> this is html comment it' not a jsp commnet.

jsp comments look ile <%-- some thing --%>

the container won't ignore the html comments at translation time. only browser will ignore at page rendering time
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But still according to the answer choices, anyways the date is inside the HTML comment, so the browser will actually ignore it totally. So 2) The user won't see the comment is correct

Try it and you will find the answer!
 
Joshua Antony
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jothi,

Pls remember that the question was if the user can see the comment if he takes a look at the page source code?

Go to view->Page Source(In Mozilla) or view->Source(IE) and you can see the comment.

Regards,
Joshua
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops...I'm sorry....I didn't read the question properly. All the questions that we have come across so far have only asked us to tell what results in the broswer....Anyways thanks for pointing out my mistake and now I'll be aware of such questions as well.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I thought comments will be ignored when jsp is converted to a servlet.

Nope. Scriptlets inside HTML/XML comments will still be evaluated by the container. JSP comments will be completely ignored, and they look like this :
 
Joshua Antony
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For further clarification:

<!-- Today is <%= new java.util.Date() %>.Hava a nice day --> is translated to the below code in the resulting java file.

out.write("<!-- Today is ");
out.print( new java.util.Date() );
out.write(".Hava a nice day -->\r\n");


Regards,
Joshua
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic