要答辩咯急啊 在线等 用jspsmart编写的东西 怎么老出错啊
是从例子该过来的 就是把上传文件的信息存入数据库但不存文件
<%@ page language= "java " import= "com.jspsmart.upload.* "%>
<%@include file= "conn.jsp "%> //提供了数据库的连接statement等的初始化
<jsp:useBean id= "mySmartUpload " scope= "page " class= "com.jspsmart.upload.SmartUpload " />
<HTML>
<BODY>
<H1> jspSmartUpload : Sample 2 </H1>
<HR>
<%
String zh=(String)session.getAttribute( "ZGBH ");
int ZGBH=Integer.parseInt(zh);
// Variables
int count=0; //这里eclipse老报错Duplicate local variable count说是重载了变量
// Initialization
mySmartUpload.initialize(pageContext);
// Upload
mySmartUpload.upload();
// Select each file
for (int i=0;i <mySmartUpload.getFiles().getCount();i++){
// Retreive the current file
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
if (!myFile.isMissing()) {
// Save the files with its original names in a virtual path of the web server
myFile.saveAs( "/upload/ " + myFile.getFileName());
String filename=myFile.getFileName();
String fileext=myFile.getFileExt();
int filesize=myFile.getSize();
String sql= "insert into ZZ_GRWJB values( ' "+ZGBH+ " ', ' "+filename+ " ', ' "+fileext+ " ', ' "+filesize+ " ') ";
stmt.executeUpdate(sql);
count ++;
}
}
%>
<script language= "javascript ">
alert( "ok ");
window.navigate( "wjliebiao.jsp ");
</script>
</BODY>
</HTML>
运行时的报错为
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 15 in the jsp file: /doupload.jsp
Duplicate local variable count
12: int ZGBH=Integer.parseInt(zh);
13:
14: // Variables
15: int count=0;
16:
17: // Initialization
18: mySmartUpload.initialize(pageContext);
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
没修改前调试正确也没报 count的错
可是改了一下就老出错 很急啊 要答辩咯。那位达人指点一下。不甚感激。
[解决办法]
变量重复定义。将count改了再试。
或将conn.jsp等相关页面贴出来。
[解决办法]
应该是你在conn.jsp中也声明了count变量,给其中的一个改名字
[解决办法]
他既然报了那个错,就该了变量再试啊,没什么好急的
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html