<%@ page language="java" %> The Following are the contents of test.jsp 1 <html> 2 <head><title>A Comment Test</title></head> 3 <body> 4 <h2>A Test of Comments</h2> 5 <!-- This is Html Hidden Comment --> 6 <%-- This is JSP Hidden Comment --%> 7 </body> 8 </html> On executing test.jsp guess the correct output a) Line 5 is inserted in response but Line 6 is not inserted in response b) Line 5 and Line 6 are inserted in response c) Both Line 5 and Line 6 are not inserted in response d) Line 5 is not inserted in response but Line 5 is inserted in response --------------------- The anwser it gave me is a). But I think it is c) and I grabbed the above code and tested it. neither line 5 nor line 6 was displayed.
Any comment? Thanks, On executing test.jsp guess the correct output
Hi, The reason is <%-- is a comment of Jsp --%> compiler ignores these statments, so line 5 is not inserted in response. <!-- is a comment of HTML --> compiler will insert statement as out.println("<!-- ... -->") into response. Regards adous
Regards<br />Adous<br />Sun Certified Programmer for Java 2 platform<br />Sun Certified Web Component Developer for J2EE
Let me add this to what adous_sg (name not according to the naming policy) said, <!-- date is <%=new java.util.Date()%> --> If you have the above line in your jsp, you will not see any out put on your browser because it is an HTML comment. However, your Servlet engine will process this (because IT IS INCLUDED in the response) and produce date and put the date in HTML comment. So if you see VIEW SOURCE, you should see <!-- date is Sunday (actual date).... --> If you have <%-- something --%>, it is considered as JSP comment, servlet engine will not even process it and hence will not include in the response. Conclusion: Answer is (a)