include指令与include动作到底有什么区别

anfield 2003-05-12 09:36:42

请看如下简单的代码:

代码1:(使用include 指令)

<%@ page contentType="text/html charset=gb2312" %>
<%@ include file="show_link.jsp" %>

编译时出现如下错误信息:org.apache.jasper.JasperException: /show_link.jsp(0,0) Page directive: can't have multiple occurrences of contentType

去掉第一行,编程成功。

代码2:(使用 include 动作)

<%@ page contentType="text/html charset=gb2312" %>
<jsp:include page="show_link.jsp" />

编译成功。

到底这两个include的用法有什么区别?为什么第一段代码有了
<%@ page contentType="text/html charset=gb2312" %>就报错?

...全文
182 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
pirateRocy 2003-05-13
  • 打赏
  • 举报
回复
那是你在show_link.jsp 中也有<%@ page contentType="text/html charset=gb2312" %>
重复了,所以报错。
anfield 2003-05-13
  • 打赏
  • 举报
回复
但为什么
<%@ page contentType="text/html charset=gb2312" %>
<%@ include file="show_link.jsp" %>

编译时出现如下错误信息:org.apache.jasper.JasperException: /show_link.jsp(0,0) Page directive: can't have multiple occurrences of contentType
chenqing1128 2003-05-13
  • 打赏
  • 举报
回复
aleccheung 2003-05-13
  • 打赏
  • 举报
回复
指令是把嵌入页面的内容都拿到主页面里面编译,
而动作是指他自身编译后再放到里面去。
下面是测试:
a.jsp
<%
String s="afa";
%>
b.jsp
<%
String s="aaaf";
%>
如果用指令就会提示变量重复,
如果用动作就能编译通过.
yefc 2003-05-12
  • 打赏
  • 举报
回复
一个是动态,一个时静态
baggio785 2003-05-12
  • 打赏
  • 举报
回复
这么用应该是没错误的,但是你写错了,少了一个分号,应该是这么写
<%@ page contentType="text/html;charset=gb2312"%>
baggio785 2003-05-12
  • 打赏
  • 举报
回复
这么用应该是没错误的,但是你写错了,少了一个分号,应该是这么写
<%@ page contentType="text/html;charset=gb2312"%>

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧