带空格的gwtuploader文件错误

时间:2013-03-09 08:14:33

标签: java gwt gwtupload

我遇到MultiUploader()对象上传文件的问题。一切都很好但是当文件有空格时,上传者停止了他的工作。有人可以帮忙吗?

我的servlet文件上传:

public class MultimediaUpload extends UploadAction {

private static final long serialVersionUID = 1L;

Hashtable<String, String> receivedContentTypes = new Hashtable<String, String>();
/**
 * Maintain a list with received files and their content types.
 */
Hashtable<String, File> receivedFiles = new Hashtable<String, File>();

/**
 * Override executeAction to save the received files in a custom place and
 * delete this items from session.
 */
@Override
public String executeAction(HttpServletRequest request, List<FileItem> sessionFiles) throws UploadActionException {
    String response = "";

    for (FileItem item : sessionFiles) {

        if (false == item.isFormField()) {

            try {

                String path = System.getProperty("catalina.home") + System.getProperty("file.separator") + "webapps" + System.getProperty("file.separator") + "data"
                        + System.getProperty("file.separator") + "images" + System.getProperty("file.separator");

                String tip = item.getName().substring(item.getName().lastIndexOf("."));

                File file = new File(path + new Date().getTime() + tip);

                item.write(file);

                // / Save a list with the received files
                receivedFiles.put(item.getFieldName(), file);
                receivedContentTypes.put(item.getFieldName(), item.getContentType());

                // / Send a customized message to the client.

                response += file.getName();

            } catch (Exception e) {

                throw new UploadActionException(e);
            }
        }
    }

    // / Remove files from session because we have a copy of them
    removeSessionFileItems(request);

    // / Send your customized message to the client
    return response;
}

/**
 * Get the content of an uploaded file.
 */
@Override
public void getUploadedFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String fieldName = request.getParameter(UConsts.PARAM_SHOW);
    File f = receivedFiles.get(fieldName);
    if (f != null) {
        response.setContentType(receivedContentTypes.get(fieldName));
        FileInputStream is = new FileInputStream(f);
        copyFromInputStreamToOutputStream(is, response.getOutputStream());
    } else {
        renderXmlResponse(request, response, XML_ERROR_ITEM_NOT_FOUND);
    }
}

/**
 * Remove a file when the user sends a delete request.
 */
@Override
public void removeItem(HttpServletRequest request, String fieldName) throws UploadActionException {
    File file = receivedFiles.get(fieldName);
    receivedFiles.remove(fieldName);
    receivedContentTypes.remove(fieldName);
    if (file != null) {
        file.delete();
    }
}

}

我的客户方:

MultiUploader defaultUploader = MultiUploader();
defaultUploader.setHeight("200");
defaultUploader.setValidExtensions(".jpg", ".png", ".gif");

我将此添加到我的面板中。

0 个答案:

没有答案
相关问题