问题
How to comment the code in jspx page? I have tried several methods,
<!-- -->
<%-- -->
but it doesn't not work!
So I have to:
<c:if test="${false}">code</c:if>,
it is really urgly, Is there any other ways? Any help is appreciated!
回答1:
JSP.1.5.2 Comments in JSP Documents
Comments in JSP documents use the XML syntax... The body of the content is ignored completely. [3]
CDATA sections may occur anywhere character data may occur; they are used to escape blocks of text containing characters which would otherwise be recognized as markup. [4]
- java.sun.com/products/jsp/syntax/2.0/syntaxref203.html#1004313
- java.net/jira/browse/JSP_SPEC_PUBLIC-105
- http://jsp.java.net/spec/jsp-2_1-fr-spec.pdf
http://www.w3.org/TR/REC-xml/#sec-cdata-sect
<![CDATA[<!-- comment -->]]>
回答2:
Just use <!-- comment -->
for comments. JSPX file uses XML syntax so that's the reason XML style comment work here.
Also read article Creating a JSP Document for understanding the difference between JSP standard syntax and XML syntax
回答3:
You were close with one of your attempts, JSP comments look like below:
<%-- some commented out stuff --%>
回答4:
Have you tried XML IGNORE?
<![IGNORE[
<!-- commented out XML -->
]]>
Change IGNORE to INCLUDE when you want it back.
回答5:
There are 2 kinds of comments: JSP comments and HTML comments.
JSP commet:
<%-- comment text --%>
HTML/XML comment:
<!-- comment -->
JSP comments are not exported to HTML and are ignored by the JSP Engine.
HTML comments are exported to HTML because they are valid HTML tags.
来源:https://stackoverflow.com/questions/3022015/how-to-comment-in-jspx-page