【发布时间】:2012-10-19 13:36:55
【问题描述】:
我现在正在尝试用jsp做一个小网站,就像大多数索引页面一样,我网站的索引页面将包括一些部分:顶部(包含徽标和菜单),主要部分,底部部分。为了避免过多的html标签填充到索引页面中,也许包含页面会是一个好主意。
经过搜索,我知道包含jsp页面有两种方法:使用<%@ include file=""%>或<jsp:include page="">,我知道它们之间存在一些差异,但我仍然遇到包含页面的一些问题。
如果我有index.jsp 和top.jsp,我想在index.jsp 中包含top.jsp。
index.jsp 是这样的:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>title</title>
<style type="text/css">
body {background-color:black;margin:0px;padding:0px;}
#left,#right {width:10%;margin:0px;padding:0px;}
#left,#center,#right {float:left;}
#center {width:80%;}
#top {height:150px;}
#main {height:600px;background-color:white;}
</style>
</head>
<body>
<div id="left"> </div>
<div id="center">
<div id="top"><jsp:include page="top.jsp"/></div>
<div id="main"></div>
<div id="bottom"></div>
</div>
<div id="right"> </div>
</body>
</html>
top.jsp 像这样:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="logo"><img width="80px" height="65px" src="images/logo.jpg"></div>
<div id="menu">
<p>
<a href="">hello</a>
<a href="">work</a>
<a href="">contact me</a>
</p>
</div>
</body>
</html>
我的问题如下:
1.无论我使用这两种方法中的哪一种,我在浏览器中点击“查看源代码”,我都得到了这个:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>title</title>
<style type="text/css">
body {background-color:black;margin:0px;padding:0px;}
#left,#right {width:10%;margin:0px;padding:0px;}
#left,#center,#right {float:left;}
#center {width:80%;}
#top {height:150px;}
#main {height:600px;background-color:white;}
</style>
</head>
<body>
<div id="left"> </div>
<div id="center">
<div id="top"><html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="logo"><img width="80px" height="65px" src="images/logo.jpg"></div>
<div id="menu">
<p>
<a href="">hello</a>
<a href="">work</a>
<a href="">contact me</a>
</p>
</div>
</body>
</html>
</div>
<div id="main"></div>
<div id="bottom"></div>
</div>
<div id="right"> </div>
</body>
</html>
top.jsp 中的代码包含头部的内容出现在index.jsp 中,我想也许我犯了一些错误,应该是这样的。
2.如果我只写一些这样的标签:
<div id="logo"><img width="80px" height="65px" src="images/logo.jpg"></div>
<div id="menu">
<p>
<a href="">hello</a>
<a href="">work</a>
<a href="">contact me</a>
</p>
</div>
那么如果代码中包含一些“ISO-8859-1”不支持的字符,myeclipse会报错信息对话框。 那么我应该如何正确地包含一个jsp页面呢? 谢谢!
刘鹏
【问题讨论】: