Jsp
//java脚本段 <% Java代码 %>
//java声明全局变量,方法类等 <%! %>
//输出表达式,数值等等 <%= %>
//静态包含
<% @include filr=""%>
将内容直接替换,只会生成一个源码文件,最终内容全部在_jspService中(源码文件),不能出现同名变量,运行效率高一点点,不灵活
//动态包含
<jsp:include page=""></jsp:include>
<!--效率高,耦合度低,标签之间不能加任何参数,如果有参数,使用动态包含传递参数,>
<%
//设置page范围的域对象(在当前页面有效,在其它页面无效)
// pageContext.setAttribute("", "");
//设置request范围的域对象(一次请求中有效,服务端跳转有效,客户端跳转失效)
request.setAttribute("name2", "sdqa");
//设置session范围的域对象(一次会话中有效)
session.setAttribute(" ", " ");
//设置application范围的域对象(整个应用中有效)
application.setAttribute("", "");
%>
<%--jsp中服务端跳转--%>
<jsp:forward page=""></jsp:forward>
<%--跳转方式
1.服务端跳转
<jsp:forward page=""></jsp:forward>
2.客户端跳转
超链接
--%>
EL表达式默认从小到大的范围去找,用法是${变量名}
获取page范围:${pageScope.变量名}
获取request范围:${requestScope.变量名}
获取session范围${sessionScope.变量名}
获取application范围${application.变量名}
判断是否为空
${empty str}如果str是空或者null或者值正确,返回true
=====================================================================
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>登录</title>
</head>
<body>
<%--test条件判断,操作的是域对象
var:限域变量名(存放在作用域中的变量名)用来接收判断结果的值(可选属性)
scope:限域变量名的范围(page,request,session,application)
--%>
<%
request.setAttribute("num", 10);
%>
<c:if test="${num>0}" var="flag" scope="request"></c:if>
${flag} -- ${sessionScope.flag}
</body>
</html>
=======================================================================
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>登录</title>
</head>
<body>
<c:choose>
<c:when test="${score<60}">
<h2>你个雄安渣渣</h2>
</c:when>
<c:when test="${score==60}">
<h2>你很不错哦</h2>
</c:when>
<c:otherwise>
<h3>你很不错</h3>
</c:otherwise>
</c:choose>
</body>
</html>
======================================================================
<%@ page import="java.util.List" %>
<%@ page import="com.example.servlet01.Student" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>测试</title>
</head>
<body>
<%--
1.迭代主体内容多次
var 限域变量名
begin 开始
end 结束
step 步长
items:要循环的数据
--%>
<%
List<Student> Stu = new ArrayList<>();
Student s1 = new Student("钟林", "18862676656", "王道同调是");
Student s2 = new Student("王者", "15564689978", "Gish后");
Student s3 = new Student("网啊往往", "人的发射点发生", "儿童与");
Stu.add(s1);
Stu.add(s2);
Stu.add(s3);
request.setAttribute("user", Stu);
%>
<%--循环对象集合--%>
<c:if test="${!empty user}">
<c:forEach items="${user}" var="us">
<tr align="center">
<td>${us.XH}</td>
<td>${us.teleno}</td>
<td>${us.name}</td>
</tr>
</c:forEach>
</c:if>
</body>
</html>