JSP基本语法

菜鸟教程

定制错误页面

法一:在web.xml

    <error-page>
        <error-code>404</error-code>
        <location>/error/404.jsp</location>
    </error-page>


    <error-page>
        <error-code>500</error-code>
        <location>/error/500.jsp</location>
    </error-page>

法二:在jsp页面

<%@ page errorPage="error/500.jsp" %>

提取公共页面

转化为一个页面

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<%@include file="common/header.jsp"%>
<h1>我是主体</h1>
<%@include file="common/footer.jsp"%>

</body>
</html>

拼接为一个页面,本质还是三个

因此可以在不同页面中定义同名变量

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<%--jsp标签--%>
<jsp:include page="common/header.jsp"/>
<h1>网页主体</h1>
<jsp:include page="common/footer.jsp"/>

</body>
</html>
两种方式的不同
1

header.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<h1>我是头部</h1>
<%
int a = 10 ;
%>

index.jsp

<%@include file="common/header.jsp"%>
<%= a %>
<h1>我是主体</h1>
<%@include file="common/footer.jsp"%>

index_jsp.java
在这里插入图片描述

2

header.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<h1>我是头部</h1>
<%
int a = 10 ;
%>

index.jsp

<body>
<%--jsp标签--%>
<jsp:include page="common/header.jsp"/>
<h1>网页主体</h1>
<%= a %>
<jsp:include page="common/footer.jsp"/>
</body>

在这里插入图片描述
由于a没有在此java中定义,因此报错

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值