错误信息: 2009-6-7 20:39:45 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 10 in the jsp file: /scxz/file_upload_smart_do.jsp SmartUpload cannot be resolved to a type 7: <body> 8: <div align="center"> 9: <% 10: SmartUpload su=new SmartUpload(); 11: su.initialize(pageContext); 12: su.setMaxFileSize(1000000); 13: su.setTotalMaxFileSize(4000000); An error occurred at line: 10 in the jsp file: /scxz/file_upload_smart_do.jsp SmartUpload cannot be resolved to a type 7: <body> 8: <div align="center"> 9: <% 10: SmartUpload su=new SmartUpload(); 11: su.initialize(pageContext); 12: su.setMaxFileSize(1000000); 13: su.setTotalMaxFileSize(4000000); An error occurred at line: 24 in the jsp file: /scxz/file_upload_smart_do.jsp com.jspsmart.upload.File cannot be resolved to a type 21: out.println("<font color=red>"+count+"</font>个文件上传成功!<br>"); 22: for(int i=0;i<su.getFiles().getCount();i++) 23: { 24: com.jspsmart.upload.File file=su.getFiles().getFile(i); 25: /*if(file.isMisssing()) 26: { 27: coutinue; Stacktrace: at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92) at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330) at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:316) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:294) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:281) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Unknown Source)
第一,你的jspSmartUpload.jar必须要在lib目录下给你参考下我以前的上传示例把。<% SmartUpload su = new SmartUpload(); //初始化 su.initialize(pageContext); //pageContext.setAttribute("uname","zhangsan",PageContext.APPLICATION_SCOPE); //设置文件大小 su.setMaxFileSize(10 * 1024 * 1024); //上传
http://book.csdn.net/bookfiles/570/10057018782.shtml图文形式的
2、jspsmartupload的jar组件拷贝一份放到tomcat6.0 的lib下
<%@ page language="java" import="xiaoxiang.fileUpload.*"%>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page errorPage="error.jsp"%>
<%@ page import="java.io.File"%>
<%
if (session.getAttribute("admin")==null || session.getAttribute("admin")==""){
response.sendRedirect("login.jsp");
} %>
<!-- 初始化一个upBean-->
<jsp:useBean id="myUpload" scope="page" class="xiaoxiang.fileUpload.upBean" />
<%
//初始化工作
myUpload.initialize(pageContext);
//设定允许的文件后缀名
myUpload.setAllowedExtList("gif,jpg,doc,txt,rm"); //设定允许上传的文件类型
// myUpload.setAllowedFileTypeList("gif,pjpeg,msword"); //设定是否允许覆盖服务器上的同名文件
//myUpload.setIsCover(false);
//设定允许上传文件的总大小
//myUpload.setTotalMaxFileSize(1000000); //设定单个文件大小的限制
//myUpload.setMaxFileSize(100000); String[] sourceName={"","",""}; //文件的原始文件名数组
String setRealPath=new String("");
//设定上传的物理路径
//myUpload.setRealPath(application.getRealPath(File.separator+"example"+File.separator+"e2_uploadFiles"));
// myUpload.setRealPath(application.getRealPath(File.separator+File.separator+"e2_uploadFiles"));
try
{
//将所有数据导入组件的数据结构中
myUpload.upload();
}
catch(Exception e){throw e;} //得到所有上传的文件
files myFiles=myUpload.getFiles();
//将文件保存到服务器
try
{ for(int i=0;i<myFiles.getCount();i++)
{
sourceName[i]=myFiles.getFile(i).getName(); //有两种保存方法,一种是保存在myUpload.setRealPath()的设定路径中,使用saveAs(),一种是另外保存到其他文件夹,使用.saveAs(String realPath)
//gif类型的文件放到gif文件夹,jpg类型的文件放到jpg文件夹
//if(myFiles.getFile(i).getExtName().equals("doc"))
setRealPath=application.getRealPath(File.separator+File.separator+"uploadFiles"+File.separator);
// else if(myFiles.getFile(i).getExtName().equals("gif") || myFiles.getFile(i).getExtName().equals("jpg"))
//setRealPath=application.getRealPath(File.separator+File.separator+"e2_uploadFiles"+File.separator+"pic");
myFiles.getFile(i).saveAs(setRealPath);
}
}
catch (Exception e) {throw e;}%>
<html>
<head>
<title>上传结果</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel='stylesheet' href='style.css' type='text/css'>
</head>
<body bgcolor="#999999" style="margin:0;">
<table border="0" cellspacing="0" cellpadding="0" width="778" height="64%" align=center style="border-right:1 solid black;border-left:1 solid black;">
<tr>
<td valign=top bgcolor="#D6EAFF">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td background="image/top_bg.gif" style="padding-left:39">
</td>
</tr>
<tr><td height="11" bgcolor="#ffffff"></td></tr>
<tr>
<td style="padding-top:20;">
<div ></div>
<table border="0" cellspacing="1" cellpadding="5" width="500" align=center bgcolor="#3A6EA5">
<th style="color:white" colspan=2>上传文件成功</th>
<tr bgcolor="#FFFFCC">
<td colspan=2>与上传的文件相关的信息</td>
</tr>
<tr bgcolor="#ffffff">
<td bgcolor="#C4DFFB">共上传文件数</td>
<td bgcolor="#E9F4FF"><%out.print(myFiles.getCount());%></td>
</tr>
<tr bgcolor="#ffffff">
<td bgcolor="#C4DFFB">原文件名:</td>
<td bgcolor="#E9F4FF">
<%
for(int i=0;i<sourceName.length;i++)
{
out.print(sourceName[i]);
out.print("<br>");
}
%>
</td>
</tr>
<tr bgcolor="#ffffff">
<td bgcolor="#C4DFFB">存到服务器上的文件名:</td>
<td bgcolor="#E9F4FF">
<%
for(int i=0;i<myFiles.getCount();i++)
{
out.print("<textarea>uploadFiles/"+myFiles.getFile(i).getName()+"</textarea><button onclick=window.clipboardData.setData('text',this.previousSibling.value)>copy</button> <br>("+(myFiles.getFile(i).getSize()/1000+1)+"kb)");
out.print("<br>");
}
%>
</td>
</tr>
<tr>
<td bgcolor="#C4DFFB">文件总共大小:</td>
<td bgcolor="#E9F4FF">
<%=(myFiles.getSize()/1000+1)+"kb"%></td>
</tr>
</table>
<BR><BR>
</td>
</tr> </table>
</td>
<td width="11" bgcolor="#ffffff"></td>
<td width="132" background="image/right_bg.gif"></td>
</tr>
</table>
</body>
</html>
还要看你是在Jsp里面用这个上传组件还是在servlet里面配置,两者稍稍有点区别:
若是jsp里面,有行代码为su.initialize(pageContext,request,response);
若是servlet里面,就应该是su.initialize(servletConfig,request,response);还有就是提交上传的那个form的属性要设置enctype="multipart/form-data"
2009-6-7 20:39:45 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 10 in the jsp file: /scxz/file_upload_smart_do.jsp
SmartUpload cannot be resolved to a type
7: <body>
8: <div align="center">
9: <%
10: SmartUpload su=new SmartUpload();
11: su.initialize(pageContext);
12: su.setMaxFileSize(1000000);
13: su.setTotalMaxFileSize(4000000);
An error occurred at line: 10 in the jsp file: /scxz/file_upload_smart_do.jsp
SmartUpload cannot be resolved to a type
7: <body>
8: <div align="center">
9: <%
10: SmartUpload su=new SmartUpload();
11: su.initialize(pageContext);
12: su.setMaxFileSize(1000000);
13: su.setTotalMaxFileSize(4000000);
An error occurred at line: 24 in the jsp file: /scxz/file_upload_smart_do.jsp
com.jspsmart.upload.File cannot be resolved to a type
21: out.println("<font color=red>"+count+"</font>个文件上传成功!<br>");
22: for(int i=0;i<su.getFiles().getCount();i++)
23: {
24: com.jspsmart.upload.File file=su.getFiles().getFile(i);
25: /*if(file.isMisssing())
26: {
27: coutinue;
Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:316)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
SmartUpload su = new SmartUpload();
//初始化
su.initialize(pageContext);
//pageContext.setAttribute("uname","zhangsan",PageContext.APPLICATION_SCOPE);
//设置文件大小
su.setMaxFileSize(10 * 1024 * 1024);
//上传
su.upload();
String musicname = su.getRequest().getParameter("type11");
String musicid=su.getRequest().getParameter("type22");
MemberPO memberPO = (MemberPO) session.getAttribute("memberPO");
MusicBO musicBO=new MusicBO();
int count = su.save("F:\\wuyao\\user\\" + memberPO.getMname()+ "\\musictype\\"+musicname+"\\" );
Files f = su.getFiles();
if(count>0)
{
for(int i=0;i<6;i++)
{
MusicPO musicPO=new MusicPO();
musicPO.setMcontent("");
musicPO.setMmusictypeid(Integer.parseInt(musicid));
musicPO.setMname(su.getRequest().getParameter("music"+(i+1)));
musicPO.setMpath("F:\\wuyao\\user\\" + memberPO.getMname()+ "\\musictype\\"+musicname+"\\"+su.getRequest().getParameter("music"+(i+1)));
musicPO.setMsininger("");
if(su.getRequest().getParameter("music"+(i+1)).length()!=0&&f.getFile(i).getFilePathName().length()!=0&&musicBO.AddMusic(musicPO)>0)
{
out.print(su.getRequest().getParameter("music"+(i+1))+"音乐上传成功<br>");
}
}
out.print("总计上传成功"+count+"个文件<a href='view/uploadmusic.jsp'><p>返回</a>");
}else
{
out.print("上传失败<br><a href='view/uploadmusic.jsp'>返回</a>");
}
%>
解压,应该要jspSmartUpload.jar
2.
jspSmartUpload.Zip
和jspSmartUpload.jar不一样么?