Hey there! In this post, we are going to cover commenting in JSP. 

 

There are two types of commenting in JSP: JSP Script Comments and JSP Script Comments. 

In terms of JSP Comments, you can comment in anywhere in the JSP file. Whereas, you will only write the JSP Script Comments inside of the tags. 

Here are some examples of them. Let's compare the comment tags with HTML too. 

<!-- HTML COMMENT -->
<%-- JSP COMMENT --%>
<% // ONE LINE COMMENT IN SCRIPTLET %>
<% /* MULTI 
		LINE 
          COMMENTS IN SCRIPTLET */ %>
<%=NAME /* EXPRESSION TAG COMMENT */ %>

COMMENT IN HTML

If the JSP tags are covered by the HTML comment tag, it won't show up on a browser, but you will see it in the source code.

<%@ page contentType = "text/html; charset=euc-kr" %>
<%@ page import = "java.util.Date" %>

<html>
<head><title>COMMENT IN HTML</title></head>
<body>

<!-- PROCESS TIME: <%= new Date() %> -->
HTML COMMENT

</body>
</html>

COMMENT IN JSP

<%@ page contentType = "text/html; charset=euc-kr" %>

<html>
<head><title>COMMENTS ON JSP</title></head>

<body>

	<%-- JSP COMMENT --%>
	JSP JSP JSP 

</body>

</html>

You will not see the JSP comment in the source code.

COMMENT IN JAVA

<%@ page contentType = "text/html; charset=euc-kr" %>

<%!
	public int add(int a, int b) {
		return a + b;
	}
%>

<html>
<head><title>COMMENT IN JAVA</title></head>

<body>

<%
	int val1 = 10; 
	int val2 = 20; 
	
	int result = add(val1, val2);
%>

<%= val1 %> + <%= val2 %> = <%= result %>

</body>
</html>

Again, you will not see the comment in the source code. 

 

So, If you want to show your comment on the source code, you have to use the html comment tag not the jsp, but if you don't want to show the comment, you have to use the jsp comment tag.

Here are some examples for your better understanding.

Example1

<%@ page contentType="text/html;charset=euc-kr" %>

<html>

<!-- HTML COMMENT-->

The result is : <br>

<%-- JSP COMMENT --%>

<body>

<%

int i=1;
int j=2;
i=i+j;

out.println("i+j = " + i); 
%>

</body>
</html>

Example2

<%@ page contentType="text/html;charset=euc-kr" %>

<html>
	<body>


<h1>Comment Example</h1>

<%
   String name = "You are my ";
%>

<!-- HTML COMMENT IS SHOWED IN THE SOURCE CODE. -->

<%-- 
This comment is not sent to the client web brower.
--%>

<!-- <%=name%> You will see this in the source code. -->

<%-- <%=name%> JSP COMMENT --%>

<%=name /* Expression tag comment*/ %> universe.

	</body>
</html>

'Java > JSP' 카테고리의 다른 글

JSP) Implicit Objects 1 - Request Object  (0) 2022.08.26
JSP) Scopes - Basics / Application  (0) 2022.08.26
JSP) Importing / Classes  (0) 2022.08.25
JSP Tags  (0) 2022.08.25
JSP  (0) 2022.08.25

+ Recent posts