3.3、關於JSP中的註釋
JSP中的註釋一定要編寫到JSP的專業註釋符號當中,只有這裏的註釋信息不會被翻譯到java源代碼當中,效率較高。其它的任何一種註釋都會被翻譯到java源代碼當中,這樣效率很低。
3.3.1、JSP的註釋語法格式:
<%--
註釋內容
--%>
————————————————
JSP文件:
<!-- This is HTML Comment -->
<script type="text/javascript">
/*
This is JavaScript Comment!
*/
/*
function sayHello(){
}
*/
</script>
<style type="text/css">
/*
This is CSS Comment!
*/
</style>
<%--
This is JSP Comment!
This is JSP Comment!
This is JSP Comment!
This is JSP Comment!
This is JSP Comment!
This is JSP Comment!
--%>
<%
//This is Java Comment!
//System.out.println("hello world!");
%>
Tomcat服務器翻譯JSP爲work目錄下項目對應Java文件的service方法:
public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException {
final javax.servlet.jsp.PageContext pageContext;
javax.servlet.http.HttpSession session = null;
final javax.servlet.ServletContext application;
final javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
final java.lang.Object page = this;
javax.servlet.jsp.JspWriter _jspx_out = null;
javax.servlet.jsp.PageContext _jspx_page_context = null;
try {
response.setContentType("text/html");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write("<!-- This is HTML Comment -->\r\n");
out.write("\r\n");
out.write("<script type=\"text/javascript\">\r\n");
out.write("\t/*\r\n");
out.write("\t\tThis is JavaScript Comment!\r\n");
out.write("\t*/\r\n");
out.write("\t/*\r\n");
out.write("\tfunction sayHello(){\r\n");
out.write("\t\r\n");
out.write("\t}\r\n");
out.write("\t*/\r\n");
out.write("</script>\r\n");
out.write("\r\n");
out.write("<style type=\"text/css\">\r\n");
out.write("\t/*\r\n");
out.write("\t\tThis is CSS Comment!\r\n");
out.write("\t*/\r\n");
out.write("</style>\r\n");
out.write("\r\n");
out.write("\r\n");
out.write("\r\n");
//This is Java Comment!
//System.out.println("hello world!");
out.write("\r\n");
out.write("\r\n");
} catch (java.lang.Throwable t) {
if (!(t instanceof javax.servlet.jsp.SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try {
if (response.isCommitted()) {
out.flush();
} else {
out.clearBuffer();
}
} catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
else throw new ServletException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
返回前臺源文件:
<!-- This is HTML Comment -->
<script type="text/javascript">
/*
This is JavaScript Comment!
*/
/*
function sayHello(){
}
*/
</script>
<style type="text/css">
/*
This is CSS Comment!
*/
</style>