开发者

Extracting parameters of a httprequest when form type is multipart

I have a requirement in which i need to process few data to generate a Id field and at the same time i need to upload a few images which needs to be done at the press of a single button.I mean to say both the data and image have to be processed(image uploaded in file server and data saved in database)at the same time.I am using apache commons to uploa开发者_JAVA技巧d the files and in the process i have set the form type as multipart.The problem is I have a few parameters set in the request itself whch when extracted in the servlet are returning null.Please provide me some pointers as to how can i extract these parameters set in request in the servlet.Please help me ..


Something like this helps you to extract the content :

DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload fileUpload = new ServletFileUpload(factory);
List<FileItem> fileUploadItems = fileUpload.parseRequest((HttpServletRequest) request);
for (FileItem fileItem : fileUploadItems) {
    String fieldName = fileItem.getFieldName();
    String contentType = fileItem.getContentType();
    long size = fileItem.getSize();
    if (size < 1) {
        throw new FileUploadException("The submitted file must not be null!");
    }
    boolean equalFieldName = fieldName.equals(SOME_FIELD_NAME);
    if (!equalFieldName) {
        // do something
    }
    boolean equalContentType = contentType.equals(SOME_CONTENT);
    if (!equalContentType) {
        // do something
    }
    if (equalFieldName && equalContentType) {
         stream = fileItem.getInputStream();
         break;
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜