将公共引入的文件放到common.jsp中,其他页面引入该jsp即可使用

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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%>">
<%@ include file="jsp/common.jsp" %>
<title>My JSP 'index.jsp' starting page</title>
</head>

此时报:Duplicate local variable basePath

  因为<%@ include file="jsp/common.jsp" %>是讲file指定的页面代码完全放入到你的页面中,这样,相当于声明了两次

<base href="<%=basePath%>">,所以报了重复的错误。

  分析:<%@ include file="" %>和<jsp:include page=""></jsp:include>区别与分析

  <%@ include file="" %>是将文件原封不动的copy进现有的文件中,像是拼接好后,再编译成为servlet运行。

  <jsp:include page=""></jsp:include>是编译后的servlet运行到该句时,跳转到指定的jsp编译的那个servlet继续运行,然后将运行结果,copy到现在的jsp中,故包含与被包含文件都是单独运行的。

  解决办法:为了达到目的,我们可以在一个jsp文件中,只声明要使用的文件的引入,而不需要指定base等,如下:

<script type="text/javascript" src="js/alert.js" charset="UTF-8"></script>
<script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.easyui.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="js/jquery-easyui-1.4.1/jquery.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="js/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js" charset="UTF-8"></script>
<link rel="stylesheet" href="js/jquery-easyui-1.4.1/themes/icon.css" type="text/css" charset="UTF-8"></link>
<link rel="stylesheet" href="js/jquery-easyui-1.4.1/themes/color.css" type="text/css" charset="UTF-8"></link>
<link rel="stylesheet" href="js/jquery-easyui-1.4.1/themes/default/easyui.css" type="text/css" charset="UTF-8"></link>

其中js和css文件均以webapp为根指定相应的引用地址。

  此时在在index.jsp中可以使用<%@ include file="jsp/common.jsp" %>即可解决问题

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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%>">
<%@ include file="jsp/common.jsp" %>
<title>My JSP 'index.jsp' starting page</title>
</head>

jsp的<%@ include file="jsp/common.jsp" %>报错误Duplicate local variable basePath的更多相关文章

  1. JSP页面使用include指令出现 Duplicate local variable basePath

    现有三个页面 " include.jsp " " a.jsp " " b.jsp " 页面代码如下 首先是a.jsp <%@ page ...

  2. JSP :使用<%@include%>报Duplicate local variable path 错误

    今天在做商城页面,遇到问题: <%@include file="menu.jsp" %> 错误提示: Multiple annotations found at thi ...

  3. JSP 使用<%@include%>报Duplicate local variable path 错误 解决方法

    错误提示:Multiple annotations found at this line:- Duplicate local variable path- Duplicate local variab ...

  4. 解决Python报错:local variable 'xxx' referenced before assignment(引)

    解决Python报错:local variable 'xxx' referenced before assignment(引) 解决Python报错:local variable 'xxx' refe ...

  5. 洗礼灵魂,修炼python(23)--自定义函数(4)—闭包进阶问题—>报错UnboundLocalError: local variable 'x' referenced before assignment

    闭包(lexical closure) 什么是闭包前面已经说过了,但是由于遗留问题,所以单独作为一个章节详解讲解下 不多说,看例子: def funx(x): def funy(y): return ...

  6. [合集]解决Python报错:local variable 'xxx' referenced before assignment

    a = 1 def use(): print(a) #输出1 引用不会报错 a = 1 def use(): a = 3 print(a) #输出 3 重新赋值也不会报错. 局部变量会优先在函数内部去 ...

  7. JSP指令include和JSP动作元素include的区别

    include指令用于在JSP页面静态的包含一个文件,该文件可以是JSP页面.HTML页面.文本文件或者一段java代码.使用include指令的JSP页面在转换时,JSP容器会在其中插入所包含文件的 ...

  8. jsp的静态包含与动态包含:<%@ include file="" %>和<jsp:include page=""></jsp:include>区别与分析

    <%@ include file="" %>是将文件原封不动的copy进现有的文件中,像是拼接好后,再编译成为servlet运行. <jsp:include pa ...

  9. <%@ include file=""%>与<jsp:include page=""/>区别(转)

    http://www.iteye.com/topic/312500/ 我们都知道在jsp中include有两种形式,分别是Include指令:<%@ include file="&qu ...

随机推荐

  1. JavaScript语言标识符和保留字

    任何一种计算机语言都离不开标识符和保留字,下面我们将详细介绍JavaScript标识符和关键字.标识符      标识符就是给变量.函数和对象等指定的名字.构成标识符的字母是有一定的规范,JavaSc ...

  2. UI3_UITableViewDelete(多选)

    // AppDelegate.m // UI3_UITableViewDelete(多选) // // Created by zhangxueming on 15/7/14. // Copyright ...

  3. UI4_UIImageView

    // // ViewController.m // UI4_UIImageView // // Created by zhangxueming on 15/7/1. // Copyright (c) ...

  4. php魔术方法 http_build_query使用

    最近在做一个项目使用到 http_build_query 这个魔术方法很好用,它可以将一个数组转换成这样的格式: 比如 $_arr = array('action'=>'show','page' ...

  5. Java直接插入排序

    插入排序是一种最简单直观的排序算法,它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入. 算法步骤: 1)将第一待排序序列第一个元素看做一个有序序列,把第二 ...

  6. svn迁移

    一.       VisualSVN服务器迁移 场景:把A服务器备份到B服务器 方法: 1.拷贝A上Repositories文件夹到B上 2.打开B上VisualSVN Server Manager ...

  7. 解决Handler与Activity同步冲突

    这个问题可以由Handler的一个子类HandlerThread来解决. 程序参考自Mars老师的Android课程第一季第十五集. 代码以及注释有所改动,如下: package com.handle ...

  8. MongoDB Long/Int(长整型)的自增长主键 解决方案

    今朝有幸尝芒果,发现自增长ID类型有多种,唯独没有Long/Int. 一思路:1. 自建一个Collection(表,假设名为:IdentityEntity,其中字段:_id, Key, Value, ...

  9. Freemarker例子

    1.引入架包 2.写ftl文件 3.代码 hello.ftl 你好啊,${hello},今天你的精神不错! if else 语句测试 <#if num gt 18><#-- 不使用 ...

  10. 1106. Lowest Price in Supply Chain (25)

    A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone invo ...