jsp初学

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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值