jsp脚本元素
JSP Scripting element are written inside tags. These code inside
tags are processed by the JSP engine during translation of the JSP page. Any other text in the JSP page is considered as HTML code or plain text.
JSP脚本元素被写在里面 标签。 这些代码里面
标签在JSP页面转换期间由JSP引擎处理。 JSP页面中的任何其他文本都被视为HTML代码或纯文本。
Example:
例:
<html>
<head>
<title>My First JSP Page</title>
</head>
<%
int count = 0;
%>
<body>
Page Count is <% out.println(++count); %>
</body>
</html>
Just to experiment, try removing the scriplet tag from the above code and run it as JSP. You will see that everything is printed as it is on the browser, because without the scriplet tag, everything is considered plain HTML code.
为了实验起见,请尝试删除 从上面的代码中获取scriplet标记,并将其作为JSP运行。 您将看到所有内容都按浏览器的原样打印,因为没有scriplet标记,所有内容都被视为纯HTML代码。
有五种不同类型的脚本元素 (There are five different types of scripting elements)
Scripting Element | Example |
---|---|
Comment | <%-- comment --%> |
Directive | <%@ directive %> |
Declaration | <%! declarations %> |
Scriptlet | <% scriplets %> |
Expression | <%= expression %> |
脚本元素 | 例 |
---|---|
评论 | <%-评论-%> |
指示 | <%@指令%> |
宣言 | <%! 声明%> |
脚本 | <%细条%> |
表达 | <%=表达式%> |
JSP评论 (JSP Comment)
JSP Comment is used when you are creating a JSP page and want to put in comments about what you are doing. JSP comments are only seen in the JSP page. These comments are not included in servlet source code during translation phase, nor they appear in the HTTP response. Syntax of JSP comment is as follows :
当您创建JSP页面并想对所做的事情添加评论时,将使用JSP Comment。 JSP注释仅在JSP页面中可见。 这些注释在翻译阶段不包含在servlet源代码中,也不会出现在HTTP响应中。 JSP注释的语法如下:
<%-- JSP comment --%>
Simple Example of JSP Comment
JSP注释的简单示例
<html>
<head>
<title>My First JSP Page</title>
</head>
<%
int count = 0;
%>
<body>
Page Count is <% out.println(++count); %>
</body>
</html>
NOTE : Adding comments in your code is considered to be a good practice in Programming world.
注意:在编程世界中,在代码中添加注释被认为是一种好习惯。
翻译自: https://www.studytonight.com/jsp/jsp-scripting-element.php
jsp脚本元素