org.apache.jasper.JasperException: Unable to compile class for JSP: 解決辦法


org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 3 in the jsp file: /ch3-4-include1.jsp
Duplicate local variable path
1: <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
2: <%
3: String path = request.getContextPath();
4: String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5: %>
6: 


An error occurred at line: 4 in the jsp file: /ch3-4-include1.jsp
Duplicate local variable basePath
1: <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
2: <%
3: String path = request.getContextPath();
4: String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5: %>
6: 
7: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

源碼:

<!--ch3-4-include1.jsp-->

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<html>
<head>
<title>被include包含的文件</title>

</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

 

<!--ch3-4-include2.jsp-->

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<html>
<head>
<base href="<%=basePath%>">

<title>include指令實例</title>

</head>
<body>
<center>
現在的日期和時間是:<%=new Date() %>
<hr>
<%@ include file="ch3-4-include1.jsp" %>
</center>
</body>
</html>

 

 

這個錯誤是在我的這個代碼里面是ch3-4-include1.jsp文件里多了 import="java.util.*"

然后把這個import="java.util.*"刪除就不報錯誤了。再把其他多余的代碼刪掉

2: <%
3: String path = request.getContextPath();
4: String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
5: %>
6: 
7: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
類似這些的刪掉!!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM