怎样在一个表单中上传文件同时提交文本? muti然后 form 进行 post 提交 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 直接post form 你会取到页面的数据。 用表单提交即可enctype="multipart/form-data" method="post" public ActionForward insert(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { UserInfo po =new UserInfo(); DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); // 最大允许大小5M// upload.setSizeMax(1024 * 1024 * 5); String appName=request.getContextPath(); String path="../webapps"+appName+"/files/"; String purl=""; try { List<FileItem> items = upload.parseRequest((HttpServletRequest) request); for (FileItem item : items) { if (!item.isFormField()) { String fname = item.getName(); path=path+fname; purl="files/"+fname; //System.out.println(path+"$$$"+purl); File f=new File(path); if(f.getParentFile().exists()) f.getParentFile().mkdirs(); f.createNewFile(); FileOutputStream fi=new FileOutputStream(f); InputStream in=item.getInputStream(); byte buffer[] = new byte[8192]; int bytesRead=0; while ( (bytesRead = in.read(buffer, 0, 8192)) != -1){ fi.write(buffer, 0, bytesRead); } in.close(); fi.close(); }else { if("name".equals(item.getFieldName())){ String name = new String(item.getString() .getBytes("ISO-8859-1"),"UTF-8"); po.setName(name ); } if("city".equals(item.getFieldName())) { String city = new String(item.getString() .getBytes("ISO-8859-1"),"UTF-8"); po.setCity(city); } if("number".equals(item.getFieldName())) { String s=item.getString(); po.setNumber(s); po.setBirthday(subStr(s)); }; if("province".equals(item.getFieldName())) { String province = new String(item.getString() .getBytes("ISO-8859-1"),"UTF-8"); po.setProvince(province); } if("sex".equals(item.getFieldName())) { String sex = new String(item.getString() .getBytes("ISO-8859-1"),"UTF-8"); po.setSex(sex); } } } } catch (Exception e) { e.printStackTrace(); } po.setPurl(purl); service.insert(po); return mapping.findForward("susses"); } hr人力资源管理系统 求用jsp编的排课管理系统。急!!! 服务器端怎么识别通过路由上网的每台电脑 请问:如何去除<ul><li>前面的小黑点 (谢谢) 新手提问:尝试第一个hibernate遇到的问题 http state 500 求这个播放器的JS servlet读word出现乱码 请问如何替换[url]http://www.tom.com[/url] ? java学习 请问如何实现选择多个文件的功能 求一个sql sever 2008 数据库驱动程序jar 包 easyui怎么替换默认值?
enctype="multipart/form-data" method="post"
HttpServletRequest request, HttpServletResponse response) {
UserInfo po =new UserInfo();
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
// 最大允许大小5M
// upload.setSizeMax(1024 * 1024 * 5);
String appName=request.getContextPath();
String path="../webapps"+appName+"/files/";
String purl="";
try {
List<FileItem> items = upload.parseRequest((HttpServletRequest) request);
for (FileItem item : items) {
if (!item.isFormField()) {
String fname = item.getName();
path=path+fname;
purl="files/"+fname;
//System.out.println(path+"$$$"+purl);
File f=new File(path);
if(f.getParentFile().exists()) f.getParentFile().mkdirs();
f.createNewFile();
FileOutputStream fi=new FileOutputStream(f);
InputStream in=item.getInputStream();
byte buffer[] = new byte[8192];
int bytesRead=0;
while ( (bytesRead = in.read(buffer, 0, 8192)) != -1){
fi.write(buffer, 0, bytesRead);
}
in.close();
fi.close();
}else {
if("name".equals(item.getFieldName())){
String name = new String(item.getString()
.getBytes("ISO-8859-1"),"UTF-8");
po.setName(name );
}
if("city".equals(item.getFieldName()))
{
String city = new String(item.getString()
.getBytes("ISO-8859-1"),"UTF-8");
po.setCity(city);
}
if("number".equals(item.getFieldName())) {
String s=item.getString();
po.setNumber(s);
po.setBirthday(subStr(s));
};
if("province".equals(item.getFieldName())) {
String province = new String(item.getString()
.getBytes("ISO-8859-1"),"UTF-8");
po.setProvince(province);
}
if("sex".equals(item.getFieldName()))
{
String sex = new String(item.getString()
.getBytes("ISO-8859-1"),"UTF-8");
po.setSex(sex);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
po.setPurl(purl);
service.insert(po);
return mapping.findForward("susses");
}