①Directive <%@ Directive名 属性名1="属性值1" 属性名2="属性值2" ...%>
@page (常用)
<%@ page contentType="text/html;charset=Shift_JIS" %>
<%@ page contentType="text/html;charset=EUC-JP" %>
<%@ page buffer="16" autoFlush="true" %>
@include
@taglib
②Define <%! ...%>
<%! String strName = null;
final int intNum = 0; //常量的定义
private void saywelcome(String name) throw IOException{ //方法的定义
out.println("welcome to here" + name);
}
③SCRIPTLET <% ... %>
✔可以这样写
<%if (value1 == value2) { %>
html文1
<% }else { %>
html文2
<% } %>
✘但是不能这样嵌套
<%
out.println("....");
<%...%>
%>
④Expression <%= ...%>
<%= request.getParamete("strName") %> ✔
<%= value1=value2?"true2:"false" %> ✔
<%= strName ;out.print("welcomet you!"); %> ✘不能
⑤ActionTag <jsp:include> <jsp:forward><jsp:getProperty> <jsp:setProperty><jsp:useBean>
<jsp:include> <jsp:forward> 包含与转向 可以使用<%@ param ...%>传递参数 eg:
<jsp:include page="encode.jsp">
<jsp:param name="encoding" value="Shift_JIS" />
</jsp:include>
<jsp:include page="include.jsp" />与<%@ include file="include.jsp" %>区别是前者是动态,后者是静态,也就是说当include.jsp改变时,后者所在页面不改变的话不会重新读取include.jsp文件的。
<jsp:getProperty> <jsp:setProperty> 取得JavaBeans的属性
<jsp:useBean> 使用javaBeans前定义javaBeans
⑥comment <%-- jsp注释--%> <!-- html注释 -->
两种注释的区别是html注释是会被发送到客户端的,即用户通过查看网页源代码可以看见
另外<% ...%>还可以这么注释
<% /* 可以
注释
多行 */ %>
<%
//注释单行
%>