JSP include动作和指令的区别

2017-07-14  本文已影响0人  草木不语只深深绿

指令include

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

动作include

<jsp:include page="footer.jsp"/>

JSP最后会被转译成Servlet

传参

因为<b>指令<%@include%></b> 会导致两个jsp合并成为同一个java文件,所以就不存在传参的问题,在发出hello.jsp 里定义的变量,<b>直接可以在footer.jsp中访问</b>
而<b>动作<jsp:include /></b>其实是对footer.jsp进行了一次独立的访问,那么就<b>有传参的需要。</b>

hello.jsp

<%@page contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*"%>  
你好 JSP
<%=new Date().toLocaleString()%>
<jsp:include page="footer.jsp">
    <jsp:param  name="year" value="2017" />
</jsp:include>

footer.jsp

<hr>
    <p style="text-align:center">copyright@<%=request.getParameter("year")%>
</p>
上一篇 下一篇

猜你喜欢

热点阅读