JSP <%@ include file= "jsp/common.jsp"%> report error duplicate local variable BasePath

Source: Internet
Author: User

Put the publicly introduced files into the common.jsp, and the other pages introduce the JSP to use

1 <%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"%>2 <%3     StringPath=Request.getcontextpath ();4     StringBasePath=Request.getscheme ()+ "://"5             +Request.getservername ()+ ":" +Request.getserverport ()6             +Path+ "/";7 %>8 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en">9 <HTML>Ten <Head> One <Basehref= "<%=basePath%>"> A  <%@ include file="jsp/common.jsp" %>  - <title>My JSP ' index.jsp ' starting page</title> - </Head>

This report: Duplicate local variable BasePath

Because <%@ include file= "jsp/common.jsp"%> is the file specified page code is completely put into your page, so that the equivalent of two statements

<base href= "<%=basePath%>", so reported a duplicate error.

  Analysis: <%@ include file= ""%> and <jsp:include page= "></jsp:include> Differences and analysis

  <%@ include file= ""%> is to copy files intact into the existing file, such as stitching, and then compiled into a servlet run.

  <jsp:include page= "" ></jsp:include> is the compiled servlet running to that sentence, jump to the specified JSP compiled by the servlet to continue running, and then run the result, Copy to the current JSP, so that the inclusion and the included files are run separately.

Workaround: In order to achieve the goal, we can only declare the introduction of the file to be used in a JSP file, without having to specify base, and so on, as follows:

<Scripttype= "Text/javascript"src= "Js/alert.js"CharSet= "UTF-8"></Script><Scripttype= "Text/javascript"src= "Js/jquery-easyui-1.4.1/jquery.easyui.min.js"CharSet= "UTF-8"></Script><Scripttype= "Text/javascript"src= "Js/jquery-easyui-1.4.1/jquery.min.js"CharSet= "UTF-8"></Script><Scripttype= "Text/javascript"src= "Js/jquery-easyui-1.4.1/locale/easyui-lang-zh_cn.js"CharSet= "UTF-8"></Script><Linkrel= "stylesheet"href= "Js/jquery-easyui-1.4.1/themes/icon.css"type= "Text/css"CharSet= "UTF-8"></Link><Linkrel= "stylesheet"href= "Js/jquery-easyui-1.4.1/themes/color.css"type= "Text/css"CharSet= "UTF-8"></Link><Linkrel= "stylesheet"href= "Js/jquery-easyui-1.4.1/themes/default/easyui.css"type= "Text/css"CharSet= "UTF-8"></Link>

Where JS and CSS files are webapp to the root to specify the appropriate reference address.

At this point, you can use <%@ include file= "jsp/common.jsp"%> in index.jsp to solve the problem

<%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"%><%    StringPath=Request.getcontextpath (); StringBasePath=Request.getscheme ()+ "://"            +Request.getservername ()+ ":" +Request.getserverport ()+Path+ "/";%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTML><Head><Basehref= "<%=basePath%>"> <%@ include file="jsp/common.jsp" %> <title>My JSP ' index.jsp ' starting page</title></Head>

JSP <%@ include file= "jsp/common.jsp"%> report error duplicate local variable BasePath

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.