在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Java/ 使用struts1 多文件上傳時(shí)的錯(cuò)誤

使用struts1 多文件上傳時(shí)的錯(cuò)誤

使用struts多文件上傳時(shí)出現(xiàn)如下錯(cuò)誤
javax.servlet.ServletException: java.lang.RuntimeException: Unknown entity: org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFile

java.lang.RuntimeException: Unknown entity: org.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFile

上傳時(shí),只能上傳最后一張圖,然后就報(bào)上述錯(cuò)誤;

form類(lèi)如下

//照片列表
private List<FormFile> photos = new ArrayList<FormFile>();


public List<FormFile> getAllPhoto() {
    return photos;
}
public FormFile getPhotos(int i) {
    return photos.get(i);
}
public void setPhotos(int i,FormFile photos) {
    this.photos.add(photos);
}

action類(lèi)如下
AlbumForm af = (AlbumForm) form;

    FormFile photo = null;
    
    Users u= (Users)request.getSession().getAttribute("loginInfo");
    String userId =u.getId().toString();
    String albumId = request.getParameter("albumId");
    Album  album = (Album) photoServiceImp.findById(Album.class, Integer.valueOf(albumId));
    
    String webSavePath = "/images/upload/"+u.getId()+"/album/"+albumId;        
    String upPath = request.getSession().getServletContext().getRealPath(webSavePath);
    System.out.println(albumId+"--"+userId+"\r\n"+upPath+"\r\n");
    System.out.println("文件個(gè)數(shù):"+af.getAllPhoto().size());
    //循環(huán)上傳照片
    for (int i = 0; i < af.getAllPhoto().size(); i++) {
        Photo p = new Photo();
        photo = af.getPhotos(i);
        System.out.println(photo.getFileName());
        try {
            String saveName = MyFileStream.uploadFile(photo, upPath);
            p.setAddTime(new Date());
            p.setAlbum(album);
            p.setPhoto(webSavePath+"/"+saveName);
            System.out.println(webSavePath+"/"+saveName);
            photoServiceImp.save(photo);                 
        } catch (Exception e) {
            // TODO: handle exception
            throw new RuntimeException(e.getMessage());
        }
    }
    return mapping.findForward("goOneAlbumUI");

注:文件上傳類(lèi)MyFileStream,沒(méi)問(wèn)題,單文件可以上傳無(wú)誤。

html表單信息:
<form action="${pageContext.request.contextPath}/album.do?flag=addPhotos&xyz=<%=Math.random()%>" method="post"

                                        enctype="multipart/form-data">
                                        <table width="80%" cellpadding="5" cellspacing="5">
                                            <tr id="more">
                                                <td align="left" rowspan="15" width="20%" valign="top">
                                                    <font class="word3"><b>上傳照片:</b> <br /> 你可以上傳JPG,
                                                        JPEG, GIF, PNG或BMP文件。</font>
                                                </td>
                                                <td>
                                                    <input type="file" name="photos[0]" class="wby" size="40" />
                                                </td>                                                     
                                            </tr>
                                             
                                             <!-- 動(dòng)態(tài)生成 -->
                                            <tr id="add">
                                                <td>
                                                     <input type="button" value="上傳更多..." onclick="addMore()">
                                                </td>
                                            </tr>                                                                                              
                                            <tr>
                                                <td>
                                                    &nbsp;
                                                    <input type="hidden" name="albumId" value="${albumId}" />
                                                     
                                                </td>
                                                <td>
                                                    <input type="submit" class="sub" value="上傳照片"
                                                        style="width: 100px"/>
                                                    <input type="reset" class="sub" value="取消"
                                                        style="width: 60px"/>
                                                </td>
                                            </tr>

                                            <tr>
                                                <td align="center" colspan="2">
                                                    <font class="word3">每批上傳限制在10張,總大小不超過(guò)15MB,如果你上傳不了,請(qǐng)?jiān)囋嚫〉恼掌?lt;/font>
                                                </td>
                                            </tr>
                                        </table>
                                    </form>

回答
編輯回答
挽青絲
<input type="button" value="上傳更多..." onclick="addMore()">

這里沒(méi)有指定name屬性,不知道你更多的文件名保存在哪個(gè)控件里?

2017年11月12日 16:48
編輯回答
若相惜

???,沒(méi)人遇到這個(gè)問(wèn)題嗎??

找到問(wèn)題了,在保存時(shí)save(obj);我把obj放錯(cuò)了,本來(lái)應(yīng)該放domain對(duì)象;但放成,F(xiàn)ormFile對(duì)象了,

2018年1月29日 05:06