免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
用Spring實(shí)現(xiàn)文件上傳(CommonsMultipartFile)!
spring中的文件上傳實(shí)際比較容易
1、頁面中
<html>
   <body>
   <form action="upload.do" method="post"   enctype="multipart/form-data">
    <input type="file"   name="uploadfile" />
    <input type="submit" value="提交" />
   </form>
   </body>
</html>
2、修改spring的配置文件添加
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
         <property name="maxUploadSize">
             <value>1048576</value>
         </property>
     </bean>
其中class部分可以選用CommonsMutipartResolver或CosMultipartResolver,但是別忘記添加相應(yīng)的jar文件
3、對應(yīng)的控制器和實(shí)體類中無需添加uploadfile文件
4、對應(yīng)的Controller

package cn.com.babe;

import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

public class UploadAction extends SimpleFormController {
private String viewsucc;
private String viewfalse;

public String getViewsucc() {
   return viewsucc;
}

public void setViewsucc(String viewsucc) {
   this.viewsucc = viewsucc;
}

public String getViewfalse() {
   return viewfalse;
}

public void setViewfalse(String viewfalse) {
   this.viewfalse = viewfalse;
}


protected ModelAndView onSubmit(HttpServletRequest request,
    HttpServletResponse response, Object command, BindException errors)
    throws Exception {
   String view = getViewfalse();
   MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
   CommonsMultipartFile orginalFile = (CommonsMultipartFile) multipartRequest
     .getFile("uploadfile");// 表單中對應(yīng)的文件名;
   if (orginalFile != null && !orginalFile.isEmpty()) {// 如果有文章中帶有附件
    String filename = orginalFile.getOriginalFilename();
    DataOutputStream out = new DataOutputStream(new FileOutputStream(
      "c:/" + filename));// 存放文件的絕對路徑
    InputStream is = null;// 附件輸入流
    try {
     is = orginalFile.getInputStream();
     byte[] b=new byte[is.available()];
     is.read(b);
     out.write(b);
    } catch (IOException exception) {
     exception.printStackTrace();
    } finally {
     if (is != null) {
      is.close();
     }
     if (out != null) {
      out.close();
     }
    }
    view=getViewsucc();
   }
   return new ModelAndView(view, null);
}

}

通過上面的方式就可以文件上傳了。我做的只是把所有的上傳文件拷貝到c盤根目錄下,并且設(shè)置了上傳文件最大大小為1mb。
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
通用上傳下載組件commons-fileupload(基于SpringMVC框架)
jsp文件下載完整方法
Java基于socket文件傳輸示例
ffmpeg.exe與mencoder.exe實(shí)例轉(zhuǎn)換操作
web中使用POI導(dǎo)入導(dǎo)出EXCEL文件的例子
JAVA如何從一個.p12或.pfx文件中獲取公鑰和私鑰?
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服