Home >Java >javaTutorial >How to comment code on jsp page
Here we introduce the comments of various codes in JSP. css comment: /* This is the CSS comment * /; js comment: // Here is the JS comment; html comment: < !- - This is a JSP file - ->; Java comment: // Here is the java script ;JSP dynamic tag comment: <%- -Here is the JSP dynamic tag comment- -%>
##Please take a look at the example :
如下为JSP中各种注释的具体体现 <%@ page language="java" contentType="text/html; charset=UTF-8" %> <%@ page session="true" import="java.util.Date,java.text.SimpleDateFormat" pageEncoding="UTF-8" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP的三种java脚本</title> <style type="text/css"> div{ border:1px solid;/*这里是CSS注释*/ } </style> <script type="text/javascript"> function func(){ //这里是JS注释 } </script> </head> <body> <!-- 这是一个JSP文件 --> <h1>java脚本</h1> <% //这里是java小脚本,生成java类时,不做任何翻译。 定义的所有的变量都是局部变量。存在于_jspService方法中 int x = 10; //int z = x/0; System.out.println("x="+x); session.setAttribute("pageName", "index.jsp"); System.out.println(session.getAttribute("pageName")); %> <hr/> <% x++; System.out.println("x="+x); %> <h1>脚本表达式</h1> <!-- 将java的表达式的结果输出到页面 通过out.print方法 --> x=<%=x+10 %> <h1>脚本申明</h1> <%! //在生成的java代码中申明成员变量和成员方法 public void method(){ } String str = "abc"; %> <%-- 这里是JSP注释 --%> <ul> <li><a href="show.jsp?op=1">刘备</a></li> <li><a href="show.jsp?op=2">关羽</a></li> <li><a href="show.jsp?op=3">张飞</a></li> </ul> <h1>当前服务器系统时间</h1> <% Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss"); String dateStr = format.format(date); %> <%=dateStr %> <hr/> <h1>JSTL</h1> <c:out value="${pageName }"/> <h1>session中区数据</h1> <%=session.getAttribute("sname") %> </body> </html>
Summary: JSP function: simplify writing html tags, dynamically generate web page content (java code can be written in jsp) demonstration, each element in the jsp file Comments
<%- - Comments in jsp files: will not be translated into .java files - -%> <%- - HTML comments, java code cannot be commented out , however, it still works in html files - -%> <%- - java comments will be translated into .java files intact - -%> <%- - Summary: Use which type of comments you want to see in which type of file - -%>The above is the detailed content of How to comment code on jsp page. For more information, please follow other related articles on the PHP Chinese website!