Ask the problem with Struts multi-file upload

xiaoxiao2021-03-05  27

import org.apache.struts.action.ActionForm; import org.apache.struts.upload.FormFile; public class ImageUploadForm extends ActionForm {private FormFile imagePath; // Image path private String pathId; // reception Image path element ID private string imgid; // Front desk picture display element ID / ** * @return returns the imagepath. * / Public formfile getImagePath () {Return ImagePath;} / ** @Param ImagePath The ImagePath To set. * / Public void setimagepath (formfile imagepath) {this.imagepath = imagepath;}

/ ** * @Return Returns the imgid. * / Public string getimgid () {return imgid;} / ** * @Param imgid the imgid to set. * / Public void setImgid (string imgid) {this.imgid = IMGID; } / ** * @Return Returns the pathid. * / Public string getPathid () {return pathid;} / ** * @Param pathid the pathid to set. * / Public void setid (string pathid) {this.pathid = PathID }}

Import java.io.filenotfoundexception; import java.io.ioException;

Import javax.servlet.http.httpservletRequest; import javax.servlet.http.httpservletResponse;

import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts . UPLOAD.FORMFILE;

public class ImageUploadAction extends Action {public ActionForward execute (ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {ImageUploadForm imageUploadForm = (ImageUploadForm) actionForm; ImageUpload imageUpload = new ImageUpload (); String pathId = (String) imageUploadForm.getPathId () ; // front desk element ID string imgid = (string) imageuploadform.getimgid (); // front desk picture display element ID formfile = imageuploadform.getImagePath (); // picture path string filename = " None.jpg "; if (thefile! = null&&! thefile.equals (" ")) {string path = this.getServlet (). getServletContext (). getRealPath (" Upload // Congress // Picture "; filename = imageupload .getuname (thefile); try {// Upload file imageupload.upload (thefile, path, filename);} catch (filenotfoundexception e) {httpservletRequest.setttrib UTE ("exception", "" "file is not found! " e); returnctionmapping.findforward (" exception ");} catch (ioException e) {httpservletRequest.setttribute (" exception "," file upload exception! " E); Return ActionMapping.FindForward (" Exception "); }} httpServletRequest.setAttribute ( "pathId", pathId); httpServletRequest.setAttribute ( "pathId", pathId); httpServletRequest.setAttribute ( "pic", fileName); return actionMapping.findForward ( "success");}} import org. Apache.struts.upload.formfile;

import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.text.SimpleDateFormat; import Java.util.date; public class imageupload {

转载请注明原文地址:https://www.9cbs.com/read-33188.html

New Post(0)