<HEAD>
<TITLE>文件上传处理页面</TITLE>
</HEAD>
<BODY bgcolor="#ffffee">
<%
   SmartUpload su=new SmartUpload();//新建一个SmartUpload对象
   su.initialize(pageContext);//上传初始化
   su.setMaxFileSize(10000);
   su.setTotalMaxFileSize(200000);
   su.setAllowedFilesList("doc,txt");
   su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
   su.upload();
   int count=su.save("\upload");
   out.print(count+"个文件上传成功!");
  // String XMH=request.getParameter("XMH");
   //String XMH1="/"+XMH;
   //su.save("/XMH1");
   for(int i=0;i<su.getFiles().getCount();i++)
   {
   com.jspsmart.upload.File file=su.getFiles().getFile(0);
   if(file.isMissing())
   { 
     out.print("文件不存在");continue;
     }
   out.print(file.getFieldName()+"<BR>");
   out.print(file.getSize()+"<BR>");
   out.print(file.getFileName()+"<BR>");
   out.print(file.getFileExt()+"<BR>");
   out.print(file.getFilePathName());
   }
   %>
 </BODY>
</HTML>
exception org.apache.jasper.JasperException: Exception in JSP: /KYGL/cglr_insert.jsp:1714:     su.setAllowedFilesList("doc,txt");
15:     su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
16:     su.upload();
17:     su.save("\b");
18:    // String XMH=request.getParameter("XMH");
19:     //String XMH1="/"+XMH;
20:     //su.save("/XMH1");
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 17 in the jsp file: /KYGL/cglr_insert.jsp
Invalid unicode
14:     su.setAllowedFilesList("doc,txt");
15:     su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
16:     su.upload();
17:     int count=su.save("\upload");
18:     out.print(count+"个文件上传成功!");
19:    // String XMH=request.getParameter("XMH");
20:     //String XMH1="/"+XMH;
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.  这个到底错在哪里啊 su.save("\upload");这个应该是保存文件的吧

解决方案 »

  1.   

    int count=su.save("\upload");
    路径不能这么写  \是转义字符,路径不仅可以在windows用\来表示 还可以用/的  换下试试另外你用的这个上传组件有严重的内存泄露问题
      

  2.   

    改着改着出错了 /upload也不行
    org.apache.jasper.JasperException: Exception in JSP: /KYGL/cglr_insert.jsp:1714:     su.setAllowedFilesList("doc,txt");
    15:     su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
    16:     su.upload();
    17:     int count=su.save("/upload");
    18:     out.print(count+"个文件上传成功!");
    19:     out.print("TEST="+su.getRequest().getParameter("TEST")+"<BR><BR>");
    20:    // String XMH=request.getParameter("XMH");
    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      

  3.   

    int count=su.save("\upload");
    换成:
    int count=su.save("/upload");
    不过,你最好用servletContext.getRealPath("/")这样去得到一个路径吧。
      

  4.   

    我要出门下,回来再试试。我在网上找的代码 运行没问题,但是好像没有文件上传,怎么回事?
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <jsp:directive.page import="com.jspsmart.upload.SmartUpload"/>
    <jsp:directive.page import="com.jspsmart.upload.File"/><%
    try {
    SmartUpload mySmartUpload=new SmartUpload();//初始化对象
    mySmartUpload.initialize(pageContext);
    mySmartUpload.setMaxFileSize(500000000);//设置图片大小   
    mySmartUpload.setAllowedFilesList("txt,doc");//允许上传图片类型
    mySmartUpload.setDeniedFilesList("exe");//禁止上传类型
    mySmartUpload.upload();//开始上传,放到内存中
    File myFile= mySmartUpload.getFiles().getFile(0);//获取上传地址
    if (!myFile.isMissing()) //路径存在
    {
    String extname=myFile.getFileExt();//获取文件主路径
    String fileName=new Date().getTime()+"."+extname;// 产生一个唯一的文件名
    myFile.saveAs("/upload/"+fileName,mySmartUpload.SAVE_VIRTUAL);//更换路径重命名
    //request.setAttribute("message","file upload success!");
    //request.setAttribute("target","upload/"+fileName);
    }  

    catch(Exception e){
    e.printStackTrace();
    }
    %>
      

  5.   

    String dstPath = ServletActionContext.getServletContext()
    .getRealPath(this.getSavePath())
    + "\\" + this.getFileFileName()
      

  6.   

    ServletActionContext这需要哪个库文件支持啊
    ServletActionContext cannot be resolved
      

  7.   

    终于找到个可以用的
    <%@ page contentType="text/html; charset=gb2312" language="java" 
    import="java.util.*,com.jspsmart.upload.*" errorPage="" %> 
    <html> 
    <head> 
    <title>文件上传处理页面 </title> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    </head> <body> 
    <% 
    // 新建一个SmartUpload对象 
    SmartUpload su = new SmartUpload(); 
    // 上传初始化 
    su.initialize(pageContext); 
    // 设定上传限制 
    // 1.限制每个上传文件的最大长度。 
    su.setMaxFileSize(10000); 
    // 2.限制总上传数据的长度。 
     su.setTotalMaxFileSize(20000); 
    // 3.设定答应上传的文件(通过扩展名限制),仅答应doc,txt文件。 
     su.setAllowedFilesList("doc,txt,pdf"); 
    // 4.设定禁止上传的文件(通过扩展名限制),禁止上传带有exe,bat, jsp,htm,html扩展名的文件和没有扩展名的文件。 
    su.setDeniedFilesList("exe,bat,jsp,htm,html,,"); 
    // 上传文件 
    su.upload(); 
    // 将上传文件全部保存到指定目录 //int count=su.save("/upload"); 
    //out.println(count+"个文件上传成功!<br>"); // 利用Request对象获取参数之值 
    out.println("TEST="+su.getRequest().getParameter("TEST")+"<BR><BR>"); // 逐一提取上传文件信息,同时可保存文件。 
    for(int i=0;i<su.getFiles().getCount();i++) 

    com.jspsmart.upload.File file = su.getFiles().getFile(i); // 若文件不存在则继续 
    if (file.isMissing()) continue; // 显示当前文件信息
    String extname=file.getFileExt();//获取文件主路径
    String fileName=new Date().getTime()+"."+extname;// 产生一个唯一的文件名
    file.saveAs("/upload/"+fileName,su.SAVE_VIRTUAL);
    out.println("<TABLE BORDER=1>"); 
    out.println("<TR><TD>表单项名FieldName</TD><TD>"+file.getFieldName()+"</TD></TR>"); 
    out.println("<TR><TD>文件长度(Size)</TD><TD>"+file.getSize()+"</TD></TR>"); 
    out.println("<TR><TD>文件名(FileName)</TD><TD>"+file.getFileName()+" </TD> </TR>"); 
    out.println(" <TR> <TD>文件扩展名(FileExt) </TD> <TD>"+extname+" </TD> </TR>"); 
    out.println(" <TR> <TD>文件全名(FilePathName) </TD> <TD>"+file.getFilePathName()+" </TD> </TR>"); 
    out.println(" </TABLE> <BR>"); } 
    %> 
    </body> 
    </html>