Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EPractice Lab mock exam 3 question 51 (about printing a scriptlet declaration on a browser)

 
Himai Minh
Ranch Hand
Posts: 1398
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSP developer wants a comment to be visible in the final output to the browser. Which comment style needs to be used in a JSP page?
a, <!-- this is a comment -->
b. <% //this is a comment %>
c. <%-- this is a comment --%>
d. <%/**this is a comment **/%>

Answer: A
<!-- this is a comment--> is equivalent to HTML comment and it will be displayed in the browser.

When I tried option A, the "this is a comment" sentence is not printed on the browser.
None of the options are printed on the browser.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2778
174
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to check what the JSP specs say about it: JSP v2.2. chapter JSP.1.5 Comments
 
Himai Minh
Ranch Hand
Posts: 1398
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Frits, thanks for the document.
I try this in comments.jsp :

I run it, but I don't see the first line <!--this is a comment--> is output on the browser as the document mentions.
 
Himai Minh
Ranch Hand
Posts: 1398
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to this site :http://www.tutorialspoint.com/jsp/jsp_syntax.htm
<!-- this is a comment --/> is ignored by HTML.
That may explain why this is not visible on the browser.
 
Himai Minh
Ranch Hand
Posts: 1398
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know why. When I right click on the browser and select "view page source", I see this :


<html>
<body>
<!-- this is a comment -->



</body>
</html>

 
K. Tsang
Bartender
Posts: 3610
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTML comments can only be seen in the source file, not in the output. The question actually missed that you need to view source haha
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!