Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Regarding jsp comment

 
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?
 
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?
 
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
 
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE 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!
 
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: 10192
3
Mac PPC Eclipse IDE 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • 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
 
I'm full of tinier men! And a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic