在JSP中如何包含一个静态页面

如题所述

JSP中的两种包含静态页面的方法
第一种:include指令:当JSP转换成Servlet时引入指定文件

<%@ page contentType="text/html; charset=GB2312" language="java" errorPage=""%> 
<%@ include file="head.jsp"%> 
<%@ include file="body.jsp"%> 
<%@ include file="tail.jsp"%>

第二种:<jsp:include>动作元素:当JSP页面被请求时引入指定文件 

<%@ page contentType="text/html; charset=GB2312" language="java" errorPage=""%> 
<jsp:include page="head.jsp"/> 
<jsp:include page="body.jsp"/> 
<jsp:include page="tail.jsp"/>


第二种方法可以很方便的用<jsp:param>来向所包含页传递参数,方法如下: 

<%@ page contentType="text/html; charset=GB2312" language="java" errorPage=""%> 
<jsp:include page="head.jsp"/> 
<jsp:include page="body.jsp"> 
<jsp:param name="uid" value="username"/> 
<jsp:param name="pwd" value="password"/> 
</jsp:include> 
<jsp:include page="tail.jsp"/>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-08-23
JSP中的两种包含页面的方法
第一种:include指令:当JSP转换成Servlet时引入指定文件 <%@ page contentType="text/html; charset=GB2312" language="java" errorPage=""%>
<%@ include file="head.jsp"%>
<%@ include file="body.jsp"%>
<%@ include file="tail.jsp"%>
第二种:<jsp:include>动作元素:当JSP页面被请求时引入指定文件
<%@ page contentType="text/html; charset=GB2312" language="java" errorPage=""%>
<jsp:include page="head.jsp"/>
<jsp:include page="body.jsp"/>
<jsp:include page="tail.jsp"/>

第二种方法可以很方便的用<jsp:param>来向所包含页传递参数,方法如下:
<%@ page contentType="text/html; charset=GB2312" language="java" errorPage=""%>
<jsp:include page="head.jsp"/>
<jsp:include page="body.jsp">
<jsp:param name="uid" value="username"/>
<jsp:param name="pwd" value="password"/>
</jsp:include>
<jsp:include page="tail.jsp"/>本回答被提问者采纳
第2个回答  2009-08-23
<%@ include file="inc.jsp" %>用来包含一个静态文件