表单类型改成二进制之后 无法用request.getParameter方法获得 要用特殊手段以前在用commons-fileupload的时候,里面有判断是否是表单域,是的话遍历items,不过取出来需要自己去比对这个item对应表单的哪个input类型String name = xxxxxx,这样子得到的是一个参数名称 需要自己判断后取其值
解决方案 »
- 求救,https开发。。。。。
- 大家帮帮忙!
- jsp分页显示
- jstl与el结合使用,不能正常输出(!)
- spring 中的getHibernateTemplate()如何实现动态查询?
- 開發系統中見到郵件發送異常,嘗試N次了還是 不行?!! 請大家都來看看
- 学JSP要些什么硬件条件?
- 控件挡住菜单
- date类型的2005-02-15,如何得到这个日期的月份,谢谢
- 这个错误org.hibernate.MappingException: Unknown entity: cn.com.sgcc.iss.model.TempAt
- 用window.showModalDialog打开的窗口不能分页显示是怎么回事?
- 【请教】java正则表达式问题
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
int color_index = 0,size_index = 0 ;
try {
// 得到所有的表单域,它们目前都被当作FileItem
List<FileItem> items = upload.parseRequest(request);
Iterator itr = items.iterator();
// 依次处理每个表单域
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
// 如果item是正常的表单域
if (item.isFormField()) {
String name = item.getFieldName();
String value = new String(item.getString().getBytes("iso-8859-1"),"UTF-8");
System.out.println("表单域名为:"+name+"表单域值为:"+value);
}else { //不是正常的表单域就是上传文件的选择域
if (item.getName() != null && !item.getName().equals("")) { //判断是否选取了文件
String pictureName = item.getName();
String fileName;
if(item.getFieldName().equals("gd_Pictures")){
fileName = "PictureofGood"+gd_Id+pictureName.substring(pictureName.indexOf("."));
//给新商品的照片添加值
newGoods.setGd_Pictures(MyUtil.coverTime(new Date())+"/"+fileName);
}else{
fileName = "ModelPictureofGood"+gd_Id+i+pictureName.substring(pictureName.indexOf("."));
//给新商品的模特照片添加新值
gd_MPictures[i]=MyUtil.coverTime(new Date())+"/"+fileName;
//对数组添加一个值后即向后移一位
i++;
}
File file = new File(getServletContext().getRealPath("/")+savePath+"/"+MyUtil.coverTime(new Date()));
if(file.exists()){ //判断文件夹是否存在 ,如果存在则不需要建立
}
else {
file.mkdirs(); //如果不存在,则建立文件夹
}
file = new File(getServletContext().getRealPath("/")+savePath+"/"+MyUtil.coverTime(new Date())+"/"+fileName);
item.write(file);
//System.out.println("成功!!");
}else{ //未选择文件
}
}
}
你用Apache的fileupload试一试,在后台得到所有表单信息,在遍历判断该表单是正常表单域,还是文件域,
这样就可以实现你要的效果了,
这个代码是我很久以前写的 里面我删了一些 你可以参考一哈