bootstrap 实现导航栏不变 内容变

当我们在建web项目时会创建多个页面,如果每一个页面都需要通过同样的导航栏索引呈现不同的内容,我们可以建一个导航页,在其他页面中加入这个导航页,能最大实现重用率

这里介绍两种实现方法

静态包含

<%@include file="temple.jsp"%>

动态包含 

<jsp:include page="temple.jsp" flush="true"/>

首先建一个导航页


<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="description" content="">
		<meta name="author" content="">
		<link rel="icon" href="../../favicon.ico">

		<title>Dashboard Template for Bootstrap</title>

		<link href="css/bootstrap.min.css" rel="stylesheet">

		<link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">

		<link href="css/dashboard.css" rel="stylesheet">

		<script src="js/ie-emulation-modes-warning.js"></script>

	</head>

	<body>

		<nav class="navbar navbar-inverse navbar-fixed-top">
			<div class="container-fluid">
				<div class="navbar-header">
					<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
					<a class="navbar-brand" href="#">Project name</a>
				</div>
				<div id="navbar" class="navbar-collapse collapse">
					<ul class="nav navbar-nav navbar-right">
						<li>
							<a href="#">Dashboard</a>
						</li>
						<li>
							<a href="#">Settings</a>
						</li>
						<li>
							<a href="#">Profile</a>
						</li>
						<li>
							<a href="#">Help</a>
						</li>
					</ul>
					<form class="navbar-form navbar-right">
						<input type="text" class="form-control" placeholder="Search...">
					</form>
				</div>
			</div>
		</nav>

		<div class="container-fluid">
			<div class="row">
				<div class="col-sm-3 col-md-2 sidebar">
					<ul class="nav nav-sidebar">
						<li class="active">
							<a href="index.jsp">Overview <span class="sr-only">(current)</span></a>
						</li>
						<li>
							<a href="list.jsp">Reports</a>
						</li>
						<li>
							<a href="login.jsp">Analytics</a>
						</li>
						<li>
							<a href="#">Export</a>
						</li>
					</ul>
					<ul class="nav nav-sidebar">
						<li>
							<a href="">Nav item</a>
						</li>
						<li>
							<a href="">Nav item again</a>
						</li>
						<li>
							<a href="">One more nav</a>
						</li>
						<li>
							<a href="">Another nav item</a>
						</li>
						<li>
							<a href="">More navigation</a>
						</li>
					</ul>
					<ul class="nav nav-sidebar">
						<li>
							<a href="">Nav item again</a>
						</li>
						<li>
							<a href="">One more nav</a>
						</li>
						<li>
							<a href="">Another nav item</a>
						</li>
					</ul>
				</div>
				<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
					</div>
				</div>
			</div>
		</div>

		<!-- Bootstrap core JavaScript
    ================================================== -->
		<!-- Placed at the end of the document so the pages load faster -->
		<script src="js/jquery.min.js"></script>
		<script>
			window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
		</script>
		<script src="js/bootstrap.min.js"></script>
		<script src="js/holder.min.js"></script>
		<script src="js/ie10-viewport-bug-workaround.js"></script>
	</body>

</html>

然后在导航页上添加链接,在跳转页面head中添加如下代码,并添加格式

<jsp:include page="index.jsp" flush="true"/>
 <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"></div>
<html>
<head>
<base href="<%=basePath%>">
<jsp:include page="index.jsp" flush="true"/>
<title>My JSP 'update.jsp' starting page</title>
</head>

<body>

 <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
	<form action="loginservlet?op=login" method="post">
		<table>
			<tr>
				<th>姓名:</th>
				<td><input type="text" name="name"/></td>
			</tr>
			<tr>
				<th>密码:</th>
				<td><input type="text" name="password"/></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
				<button type="submit">登录</a></td>
			</tr>
		</table>
	</form>
	</div>
</body>
</html>

 实现效果如图

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页