ITPub博客

首页 > 应用开发 > Java > include 与 jsp:include jsp:forward的区别

include 与 jsp:include jsp:forward的区别

原创 Java 作者:liang573728 时间:2019-06-14 08:57:05 0 删除 编辑

include 可以直接load入文件,不能可以动态增加内容,动态赋值变量,效率高;

jsp:include 也可以load入文件,同时可以动态增加内容,动态赋值变量等.效率低;被包含的对象只有对JSP write对象的访问权,并且它不能设置头或者Cookie.如果页面输出是缓冲的,那么缓冲区的刷新要优于包含的刷新.

jsp:forward 则是直接跳转页面,并能设置变量

[@more@]

应用例子:

static.html:




static.html










please input your name:


input yor password:




===================

two.jsp:

<%@ page contentType="text/html;charset=GBK" language="java"%>


two.jsp




this is a1 = <%=request.getParameter("a1") %>


this is a2 = <%=request.getParameter("a2") %>


<%out.print("hello from two");%>

=====================

jsp_include.jsp:

<%@ page contentType="text/html; charset=gb2312" language="java" %>


<%@ include file="static.html" %>
<%//只是把文件包含进来%>
goto two-->

this examples show include works
<%
String name = request.getParameter("namet");
out.print("
"+name);
String password = request.getParameter("passwordt");
out.print("
"+password);
if(null == name) name = "null";
if(password == null) password = "null";
%>
<% if (! name.equals("kkk")){ %>




<% } %>

<% if (name.equals("kkk")){ %>




<% } %>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/640706/viewspace-1016584/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2005-10-15

  • 博文量
    152
  • 访问量
    112961