前一种方法只能上传一些小的文件.
因为写入的长度为文件的长度,假设有一个文件有 2 G
而你电脑的内存只有 1 G 你说你的这个文件怎么上传啊.
后一种每次读 8192 k 就可以麻.
因为写入的长度为文件的长度,假设有一个文件有 2 G
而你电脑的内存只有 1 G 你说你的这个文件怎么上传啊.
后一种每次读 8192 k 就可以麻.
解决方案 »
- Map不同步的问题
- 数据库建模 求高手
- 考 sun java EE 系统认证师有用吗?
- 求技术网站
- 过来人指点,我现在快毕业了,如何去规划最后一年的时间?恳求高人指点,进者接分!!!
- 安装jakarta-tomcat-5.0.29.exe失败,安装的进度条到C:\j2sdk1.4.2\jre\bin\server\jvm.dll 便停止不动了
- 怎样在 struts-config.xml 中的 给forward 标签的 path 属性传递多个参数
- tomcat5.0问两个比较低级的问题???
- 怎样在数据表中得到Insert后的自动增量字段的值?
- JAVA WEB 缓存问题
- struts 初级问题
- 新手问个SSH框架的问题
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
New_chanpinForm new_chanpinForm = (New_chanpinForm) form;// TODO FormFile file = new_chanpinForm.getImg_url(); if (("".equals(new_chanpinForm.getImg_url().getFileName())
|| (new_chanpinForm.getImg_url().getFileName() == null))) {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"chanpin_img_url_null"));
this.saveErrors(request, errors);
return mapping.getInputForward();
}
if (!((file.getContentType().equals("image/bmp"))
|| (file.getContentType().equals("image/gif"))
|| (file.getContentType().equals("image/jpg")) || (file
.getContentType().equals("image/jpeg")))) {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"file_type_wrong"));
this.saveErrors(request, errors);
return mapping.getInputForward();
} this.getChanpin_service().updateFile(request, file);////////////////****************** Chanpin chanpin = new Chanpin();
chanpin.setImgUrl("UserFiles/Image/" + file.getFileName());
chanpin.setJianjie(new_chanpinForm.getJianjie().trim());
chanpin.setMingcheng(new_chanpinForm.getMingcheng().trim()); this.getChanpin_service().save(chanpin); return mapping.findForward("list_chanpin"); }
}
updateFile方法实现如下: public void updateFile(HttpServletRequest request, FormFile formfile) {
FileOutputStream fileOutput;
try {
fileOutput = new FileOutputStream(request
.getRealPath("/UserFiles/Image")
+ "/" + formfile.getFileName());
fileOutput.write(formfile.getFileData());
fileOutput.flush();
fileOutput.close();
} catch (Exception e) {
e.printStackTrace();
} }
好像要改成saveMessages