jsp:include, include指令和<c:import/>,cookie

<jsp:include page=""/> action和<c:import url=""/> jstl tag都是动态加载。但是c:import则更为灵活。jsp:include只能include当前web app下的页面,而c:import则可以从外部容器加载内容。

 

动态加载和静态加载最根本的不同在于,jsp生成的servlet的不同。在tomcat下静态(include directive)和动态(include action)的_jspService()代码如下:

Java代码   收藏代码
  1. out.write(“<html><body>\r”);  
  2. <span style="font-family: webdings;">out.write(“\r<html>\r<body>\r<img src=\”images/Web-Services.jpg\” >  
  3. <br>\r<em><strong>We know how to make SOAP suck less.</strong></em> <br>\r\r  
  4. </body>\r</html>\r”);</span>  
  5.   
  6.   
  7. out.write(“\r<br>\r\r\r<em>We can help.</em> <br><br>\r\rContact us at: “);  
  8. out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.  
  9. proprietaryEvaluate(“${initParam.mainEmail}”, java.lang.String.class,  
  10. (PageContext)_jspx_page_context, nullfalse));  
  11. out.write(“\r\r\r</body></html>”);  

 而动态的则是:

Java代码   收藏代码
  1. out.write(“<html><body>\r”);  
  2. <span style="font-family: webdings;">org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response,  
  3. “Header.jsp”, out, false);</span>  
  4.   
  5.   
  6. out.write(“\r<br>\r\r\r<em>We can help.</em> <br><br>\r\rContact us at: “);  
  7. out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.  
  8. proprietaryEvaluate(“${initParam.mainEmail}”, java.lang.String.class,  
  9. (PageContext)_jspx_page_context, nullfalse));  
  10. out.write(“\r\r\r</body></html>”);  
 

可以看到静态的是将要include的页面直接写在了servlet里面,这样当servlet生成之后,就不能修改了。动态的则不同,运行时才会导入页面。

 

另外jsp:include和c:import可以分别使用jsp:param和c:param来设置参数来控制要include的页面。

 

 

包含进来的jsp中操作cookie,只能使用include指令才能使用包含进来的jsp的response操作cookie

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
给下面代码增加分页功能,要求细致,逻辑清楚,<form action="./../selectNews" method="post"> <input type="text" name="key" id="key" placeholder="请输入标题"/> <input type="submit" value="查询"/> <a href="zhuce.jsp">发布新闻</a> <a href="../user01/index.jsp">返回主页</a> </form> <table> <thead> <tr> <th>新闻编号</th> <th>新闻标题</th> <%-- <th>新闻内容</th>--%> <th>新闻类别</th> <th>发布人</th> <th>发布时间</th> <th>状态</th> <th>是否头条</th> <th colspan="4" align="center">操作</th> </tr> </thead> <tbody> <c:forEach items="${newslist}" var="u"> <tr> <td>${u.nid}</td> <td>${u.title}</td> <%-- <td>${u.content}</td>--%> <td>${u.type}</td> <td>${u.userName}</td> <td>${u.pubTime}</td> <td> <c:choose> <c:when test="${u.state==0}"><span style="color: ghostwhite">未审核</span></c:when> <c:when test="${u.state==1}"><span style="color: green">审核通过</span></c:when> <c:otherwise><span style="color: red">未通过</span></c:otherwise> </c:choose> </td> <td> <c:choose> <c:when test="${u.top==0}">否</c:when> <c:otherwise>是</c:otherwise> </c:choose> </td> <c:choose> <c:when test="${user.rule==1}"> <td> <a href="../NewsDetailServlet?nid=${u.nid}&op=show">查看</a> </td> <td> <a href="../NewsDetailServlet?nid=${u.nid}&op=update">修改</a> </td> <td> <a href="NewsDelete.jsp?nid=${u.nid}&title=${u.title}&userName=${user.userName}">删除</a> </td> <td> <a href="Newsshenhe.jsp?nid=${u.nid}&title=${u.title}&userName=${user.userName}">审核</a> </td> </c:when> <c:when test="${user.rule==0 && user.uid==u.uid}"> <td><a href="../NewsDetailServlet?nid=${u.nid}&op=show">查看</a></td> <td><a href="../NewsDetailServlet?nid=${u.nid}&op=update">修改</a></td> <td><a href="NewsDelete.jsp?nid=${u.nid}&title=${u.title}&userName=${user.userName}">删除</a></td> </c:when> <c:otherwise> <td><a href="../NewsDetailServlet?nid=${u.nid}&op=show">查看</a></td> </c:otherwise> </c:choose> </tr> </c:forEach> </table>
最新发布
06-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值