<%@ page contentType="text/html; charset=utf-8" language="java" 
import="java.util.*,com.jspsmart.upload.*" errorPage="" %>
<html>
<head>
<title>文件上传处理页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
    SmartUpload su = new SmartUpload();
    su.initialize(pageContext);
    .....
%>
</body>
</head>有一处错误在su.initialize(pageContext);说initialize()方法没定义,开始以为是我下的包有问题,结果换了几个还是这样。分不多了,请好心人帮忙。

解决方案 »

  1.   

    不知道 没出现你这种情况 你写在servlet里面试下::
    package com.globalarts.util;import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import com.jspsmart.upload.SmartUpload;
    import com.jspsmart.upload.SmartUploadException;public class UploadFile extends HttpServlet { private static final long serialVersionUID = 1L; private ServletConfig config; private String folderpath = ""; private String filepath = "";

    final public void init(ServletConfig config) throws ServletException {
    this.config = config;
    } @SuppressWarnings("deprecation")
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    response.setCharacterEncoding("gbk"); String dtstr = "";
    String url = "";
    String fileurl = "";
    int rd =0; SmartUpload su = new SmartUpload();
    int rs = 0;
    su.initialize(config, request, response);
    su.setMaxFileSize(1024 * 200);
    su.setAllowedFilesList("jpg,jpeg,gif,bmp,JPG,GIF,BMP,JPEG");
    try {
    su.upload();
    } catch (Exception e) {
    rs = 2; // 文件上传失败
    }
    if (rs != 2) {
    com.jspsmart.upload.File file = su.getFiles().getFile(0);
    try {
    file.saveAs(fileurl);
    } catch (SmartUploadException e) {
    e.printStackTrace();
    rd =1;
    } if(rd==0){
    PrintWriter out = response.getWriter();
    out.print("上传成功!");
    out.close();
    }
    else{
    PrintWriter out = response.getWriter();
    out.print("上传失败!");
    out.close();
    }
    }
    else{
    PrintWriter out = response.getWriter();
    out.print("上传失败,请检查图片格式与大小(200K以内)!");
    out.close();
    }
    }
    }