比如说导航栏,所有的页面都需要,如果要改的话,得一个个改,很麻烦,就把他们做成一个单独的jsp,引用即可
比如一部分html的代码,把它放在一个新成立的jsp的body内,再在原来的地方用jsp include标签引用,即可
<jsp:include page="side_buyer.jsp"></jsp:include>
但是有一种情况很麻烦,就是导航栏的数据是从数据库中取得的,不是硬编码的,里面要有传入的对象
此时
<%@ include file="header.jsp"%>
这种方法,能在编译前放入原来的jsp,之前的那种是在编译后
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<!-- Navbar -->
<nav class="main-header navbar navbar-expand bg-white navbar-light border-bottom">
<!-- Left navbar links -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" data-widget="pushmenu" href="#"><i class="fa fa-bars"></i></a>
</li>
<li class="nav-item d-none d-sm-inline-block">
<a href="${pageContext.request.contextPath}/buyer/index.do" class="nav-link">首页</a>
</li>
</ul>
<!-- Right navbar links -->
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" data-widget="control-sidebar" data-slide="true" href="#">
<i class="fa fa-th-large"></i>
</a>
</li>
</ul>
</nav>
<!-- /.navbar -->
<!-- Main Sidebar Container -->
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="${pageContext.request.contextPath}/buyer/index.do" class="brand-link">
<img src="${pageContext.request.contextPath}/conf1/dist/img/AdminLTELogo.png"
alt="AdminLTE Logo"
class="brand-image img-circle elevation-3"
style="opacity: .8">
<span class="brand-text font-weight-light">拾塘</span>
</a>
<!-- Sidebar -->
<div class="sidebar">
<!-- Sidebar user (optional) -->
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
<div class="image">
<img src="${pageContext.request.contextPath}/conf1/dist/img/user2-160x160.jpg" class="img-circle elevation-2" alt="User Image">
</div>
<div class="info">
<a href="#" class="d-block">${buyer.name }</a>
</div>
</div>
<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
<!-- Add icons to the links using the .nav-icon class
with font-awesome or any other icon font library -->
<li class="nav-item">
<a href="${pageContext.request.contextPath}/views/buyer/register.jsp" class="nav-link">
<i class="fa fa-circle-o nav-icon"></i>
<p>买家注册</p>
</a>
</li>
<li class="nav-item">
<a href="${pageContext.request.contextPath}/views/buyer/info_show.jsp" class="nav-link">
<i class="fa fa-circle-o nav-icon"></i>
<p>查看修改自身信息</p>
</a>
</li>
<li class="nav-item">
<a href="${pageContext.request.contextPath}/views/buyer/showDetailedOrder.do" class="nav-link">
<i class="fa fa-circle-o nav-icon"></i>
<p>查看订单</p>
</a>
</li>
<li class="nav-item">
<a href="${pageContext.request.contextPath}/views/buyer/money_add.jsp" class="nav-link">
<i class="fa fa-circle-o nav-icon"></i>
<p>充值</p>
</a>
</li>
</ul>
</nav>
<!-- /.sidebar-menu -->
</div>
<!-- /.sidebar -->
</aside>
</body>
</html>