JSP:Java Server Page(Java的服务网页),也是Java的动态网页. JSP的本质:其实就是一个Servlet. JSP----翻译成Servlet类----编译成字节码文件---解释执行了. 1.jsp的基本语法: 1、JSP的注释: 作用:注释
web.xml <error-page> <exception-type>java.lang.Exception</exception-type> <location>/error.jsp</location> </error-page> <error-page> <error-code>404</error-code> <location>/404.jsp</location> </error-page>/*include*/ 作用:包含其他的组件。 语法:<%@include file=""%>file指定要包含的目标组件。路径如果以"/"(当前应用)就是绝对路径。 原理:把目标组件的内容加到源组件中,输出结果。 动态包含:采用动作元素:<jsp:include page=""/>路径如果以"/"(当前应用)就是绝对路径。 /*taglib*/ 作用:引入外部的标签 语法:<%@taglib uri="标签名称空间" prefix="前缀"%> 例:<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 3.九大内置对象 4.servlet+jsp综合 5.jsp代码解说
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <%= pageContext.findAttribute("test")!=null ? pageContext.findAttribute("test") : "111" %> ${test } <%-- ${pageContext.getRequest().getContextPath()} --%> <!-- 通过实体.属性 --> <%-- ${user.username } ${user.password } --%> <!-- jsti常用标签: c:forEach: items:要循环的集合/列表 var:定义集合元素的类型 begin:从第几项开始循环 end:循环到第几项结束 step:循环的步长 varStatus:关于下标的对象 index:下标 count:成员总数 first:判断是否是第一个元素(boolean) last:最后一个元素(boolean) c:set: var:定义变量名称 value:变量的值 scope:变量的作用域 默认为:page c:remove: var:需要移除的变量名 scope:作用域 c:out: value:输出的值(相当于<%-- <%=%> --%>) c:if --> <table border="1"> <c:forEach items="${users }" var="user" varStatus="item"> <c:set var="setDemo" value="${item.index }"></c:set> <c:remove var="setDemo"/> <%-- <td> ${testDemo }</td> --%> <c:if test="${item.index > 10 }" var="testDemo"> <tr> <td> <c:out value="1"></c:out></td> <td> ${user.username }</td> <td> ${user.password }</td> </tr> </c:if> <c:choose> <c:when test="${item.index > 10 }"> <c:out value="大于10"></c:out> </c:when> <c:otherwise> <c:out value="小于等于10"></c:out> </c:otherwise> </c:choose> </c:forEach> </table> </body> </html>6.相关的导包: 7.jsp作用域范围从大到小: pageContext-->request-->session-->application 什么叫做作用域:对象的声明周期和可访问性
6.相关的导包: