其他分享
首页 > 其他分享> > JSP基础语法-关于JSP中的注释

JSP基础语法-关于JSP中的注释

作者:互联网

JSP基础语法

   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>





 

标签:注释,语法,write,JSP,jspx,servlet,javax,out
来源: https://blog.csdn.net/cheng_feng_xiao_zhan/article/details/100144461