JSP指令 标签

JSP指令

  1. JSP指令只有三个
    (1)page
        aotuFlush:自动刷新
        contentType:页面文本类型 “text/html”
        errorPage:如果存在错误页面,就跳转至指定的错误页面,可以在web.xml里面配置
        language:页面使用的语言 jsp中使用的语言默认java
        pageEncoding:页面编码
        import:导jar包 因为jsp本质就是一个servlet。
    (2)include:导入其他页面到本页,两个页面合一
        file:要导入的页面,一般都是不完整的网页,只包含部分
    (3)taglib:标签库
  2. include指令
    header.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div>
    <h1>头部信息</h1>
</div>

footer.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div>
    <h1>尾部信息</h1>
</div>

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>$Title$</title>
</head>
<body>
<%@include file="common/header.jsp"%>
<h1>我是index页面</h1>
<%@include file="common/footer.jsp"%>
</body>
</html>

在这里插入图片描述

  1. web.xml下的error-page
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <error-page>
        <location>/error/404.jsp</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
         <!--
         location:错误页面的地址
         -->
        <location>/error/500.jsp</location>
    </error-page>
    <error-page>
        <exception-type>java.lang.NullPointerException</exception-type>
        <location>/error/500.jsp</location>
    </error-page>
</web-app>
  1. jsp:include
<jsp:include page="/common/header.jsp"/>
<h1>tag标签</h1>
<jsp:include page="/common/footer.jsp"/>

在这里插入图片描述

  1. jsp:forward jsp:param
    tag.jsp
<jsp:forward page="index.jsp">
    <jsp:param name="username" value="haoyifan"/>
    <jsp:param name="age" value="18"/>
</jsp:forward>

index.jsp

名字:
<%=request.getParameter("username")%>
年龄:<%=request.getParameter("age")%>

在这里插入图片描述

  1. userbean
<jsp:useBean id="student" class="com.baidu.Student" scope="page"/>
<%
    student.setAge(1000);
    student.setName("郝一凡");

%>
<%=student.getAge()%>
<%=student.getName()%>
//等价于
<jsp:useBean id="student" class="com.baidu.Student" scope="page"/>
<jsp:setProperty name="student" property="age" value="2"/>
<jsp:setProperty name="student" property="name" value="辛卫东"/>
<jsp:getProperty name="student" property="name"/>
<jsp:getProperty name="student" property="age"/>

实体类

package com.baidu;

public class Student {
    private String name;
    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return super.toString();
    }
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值