javaweb入门基础知识jsp

根据自学网整理笔记


1.jsp指令

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="index.jsp" %>
<%@ taglib uri="xxx" prefix="c"%>

2.jsp的九大隐式对象

名称类型描述
outJspWriter页面输出
requestHttpServletRequest共享一次请求中的信息
responseHttpServletResponse服务器向浏览器回应信息
configServletConfig服务器配置,可以取得初始化参数
sessionHTTPSession会话信息共享
applicationServletContext所有用户的共享信息
pageObject指当前页面转换后的Servlet类的实例
pageContextpageContextJSP的页面容器 上下文的对象
exceptionThrowable在错误页面中才起作用

out.write(); = response.getWriter().write();

pageContext对象只在当前jsp页面有效

pageContext.setAttribute("name","xiaohong");
pageContext.setAttribute("name","xiaohong",PageContext.REQUEST_SCOPE);
pageContext.setAttribute("name","xiaohong",PageContext.SESSION_SCOPE);
pageContext.setAttribute("name","xiaohong",PageContext.APPLICATION_SCOPE);

pageContext.getAttribute("name", PageContext.SESSION_SCOPE);
//findAttribute会依次从PageContext域,request域,session域,application域中获取属性。
pageContext.findAttribute("name");

3.jsp标签

常用jsp标签

页面动态包含:
<jsp:include page="hello.jsp"></jsp:include>
请求转发:
<jsp:forward page="hello.jsp"></jsp:forward>

4.EL表达式获取域中数据

EL全名为Expression Language。它提供了在JSP中简化表达式的方法,让Jsp的代码更加简化,可以嵌入在jsp页面内部,减少jsp脚本的编写

从域中获取数据
${requestScope.name}
${sessionScope.user.name}
${applicationScope.list[0].name}

//会依次从PageContext域,request域,session域,application域中获取值。
${key}

4.1 EL内置对象

获取jsp中域中的数据
requestScope
sessionScope
applicationScope
pageScope

pageContext WEB开发中的pageContext
pageContext获取其他八大对象


不常用
param,paramValues 接收参数
相当于request.getParameter() request.getParameterValues()

header,headerValues 获取请求头信息
相当于request.getHeader(name)

cookie WEB开发中cookie
相当于request.getCookies()–>cookie.getName()—>cookie.getValue()

initParam 获取全局初始化参数
相当于this.getServletContext().getInitParameter(name)

4.2 EL的执行表达式

基本运算,三元都支持
1+1 1 + 1 {empty user}判断对象是否为空

5 JSTL

JSTL(JSP Standard Tag Library),JSP标准标签库,可以嵌入在isp页面中使用标签的形式完成业务逻辑等功能。jst1出现的目的同EL一样也是要代替jsp页面中的脚本代码。JSTL标准标准标签库有5个子库,但随着发展,目前常使用的是他的核心库。
这里写图片描述

*********if
//使用jstl表达式的时候往往需要EL表达式的配合
<c:if test="${1+1==2}">
//若test为true 则会执行内部的代码,反之false不执行
</c:if>

**********forEach
<c:forEach begin="0" end"${list.size()}" var="i">
    ${i}
</c:forEach>

<c:forEach items="${list}" var="usre">
    ${user.name}
</c:forEach>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值