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