哪位高手帮帮忙,一个关于smartupload上传的奇怪问题,小弟不才,调试了一天,还没调试出来,急啊
我从网上下了一个用smartupload上传的代码,我觉得代码应该没问题,大家可以看看,共有upload.htm和upfile.jsp两个文件。其中upload.htm中的代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
BODY{
font-size:9pt
}
-->
</style>
<SCRIPT language=javascript>
function check_file()
{
var strFileName=form1.FileName.value;
if (strFileName=="")
{
alert("请选择要上传的文件");
return false;
}
}
</SCRIPT>
</head>
<body>
<form action="upfile.jsp" method="post" name="form1" onSubmit="return check_file()" enctype="multipart/form-data">
<input name="FileName" type="FILE" size="20">
<input type="submit" name="Submit" value="上传">
</form>
</body>
</html>
而upfile.jsp中的代码为:
<%@ page contentType="text/html;charset=GB2312"
import="com.jspsmart.upload.*,
java.util.*,
java.lang.*"
%>
<jsp:useBean id="mu" scope="page" class="com.jspsmart.upload.SmartUpload" />
<HTML>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<BODY>
<%
// 初始化
final String UpFileType="zip|rar|doc|txt"; //上传文件类型
final int MaxFileSize=10240; //上传文件大小限制
String ErrMsg=null; //错误信息
boolean ERR=false; //错误标志
mu.initialize(pageContext);
// 上传文件
mu.upload();
// 取当前文件
com.jspsmart.upload.File myFile = mu.getFiles().getFile(0);
// 取得文件并保存
if (!myFile.isMissing()) {
//得到文件扩展名
String FileType=myFile.getFileExt();
FileType=FileType.toLowerCase(); //将扩展名转换成小写
if (UpFileType.indexOf(FileType)==-1){
ERR=true;
ErrMsg="上传文件失败!目前只允许上传以下格式的文件:"+UpFileType;
}
//得到文件大小
int FileSize=myFile.getSize();
if (ERR==false&&FileSize>MaxFileSize){
ERR=true;
ErrMsg="上传文件失败!文件大小超出了限定的范围(最大"+MaxFileSize/1024+"K)";
}
if(ERR==false){
//保存文件
String newFileName="001."+FileType; //可自动生成文件名以防止同名覆盖
myFile.saveAs(newFileName);
}else{
out.print ("<script>alert('"+ErrMsg+"');</script>");
}
}
%>
</BODY>
</HTML>
我的环境变量的配置是:
CLASSPATH: C:\jdk\lib\tools.jar;C:\jdk\lib\dt.jar;C:\tomcat\common\lib\servlet-api.jar
Path: C:\jdk\bin
TOMCAT_HOME: C:\tomcat
JAVA_HOME: C:\jdk
smartupload的类文件放到了当前目录的WEB-INF下的classes中,顺序如:com.jspsmart.upload,好像也没什么问题,不过运行时出现了以下错误:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax/servlet/jsp/PageContext
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.demo.upfile_jsp._jspService(upfile_jsp.java:115)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NoClassDefFoundError: javax/servlet/jsp/PageContext
com.jspsmart.upload.SmartUpload.initialize(SmartUpload.java:153)
org.apache.jsp.demo.upfile_jsp._jspService(upfile_jsp.java:75)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.0.28
想过了许多办法,也下了其它类似的上传程序试过,都是同样的错误。不过其他的jsp程序都能正常运行。我也不知道究竟什么地方出了差错,难道是什么文件的配置有误或是我的jsk,tomcat的版本出了问题