现有三个页面 " include.jsp " " a.jsp " " b.jsp "

页面代码如下

首先是a.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <%out.println("I am a.jsp"); %>

b.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <%out.println("I am b.jsp"); %>

include.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<%@ include file="a.jsp" %>
/*此处报错
- Duplicate local variable path
- Duplicate local variable basePath
- Duplicate local variable path
*/
<jsp:include page="b.jsp"></jsp:include>
</body>
</html>

但是把

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<base href="<%=basePath%>">

这两段代码删除就不会报错了

查看网上资料后了解到:include元素指令的作用发生在转换阶段,它会把a.jsp的代码包含进index.jsp;include动作指令的作用发生在执行阶段,它不会把b.jsp的代码包含到index.jsp中,而是在执行时向b.jsp发出请求,把得到的结果包含到index.jsp中。因此,查看a.jsp的源代码,发现其中有定义path,basePath变量,既然是包含源代码,那么就会和index.jsp中定义的path,basePath变量重复,这就是之前的错误提示表达的意思。

最新文章

  1. CSharpGL(27)讲讲清楚OpenGL坐标变换
  2. STM32 奇偶校验配置
  3. 【架构】How To Use HAProxy to Set Up MySQL Load Balancing
  4. Linux 中文乱码问题解决
  5. php程序员的水平 看看自己属于那个级别的
  6. elasticsearch Java API汇总
  7. ANT 环境搭建
  8. Java的正则表达式
  9. 网页爬虫--scrapy入门
  10. 安装mysql之后,存入中文出现乱码
  11. js 截取某个字符前面或者后面的字符串
  12. OpenWrt固件刷入后串口终端没有反应的问题
  13. C++中变量自动初始化的问题
  14. 哆啦A梦连连看游戏源码完整版
  15. 以后坚持用java
  16. website
  17. poj 2431
  18. .NET 多语言支持解决方案 (转)
  19. poj 3422 Kaka&#39;s Matrix Travels 费用流
  20. CRtmpServer分析与应用

热门文章

  1. 2017-11-11 Sa Oct Is it online
  2. java 调用webservice接口wsdl,推荐使用wsdl2java,放弃wsimport
  3. Mybatis的学习1
  4. PTA变成总结1
  5. ESP8266 01S WIFI 网络
  6. webpack 4.0配置
  7. 利用linux curl爬取网站数据
  8. IDEA 中tomcat日志位置
  9. vim matchit 自定义配对关键字之间的跳转
  10. HDU - 4858 项目管理