用JSPSmartUpload或common-fileupload来做
在表单里加了
ENCTYPE= "multipart/form-data "
直接用request.getParameter( "name "); 是取不到值的
因为JSPSmartUpload或common-fileupload又将参数值进行了一次封装,所以,直接取是没法取到的。
SmartUpload 取表单值值方法:
SmartUpload mySmartUpload = new SmartUpload();
mySmartUpload.initialize(config, request, response);
mySmartUpload.upload();
name = mySmartUpload.getRequest().getParameter( "name ");
common-fileupload取表单值方法:
if (FileUpload.isMultipartContent(requestContext)) {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(savaFilePath));
ServletFileUpload upload = new ServletFileUpload(factory);
// upload.setHeaderEncoding("gbk");50MB bytes
upload.setSizeMax(51200000);
List items = new ArrayList();
try {
items = upload.parseRequest(request);
} catch (FileUploadException e1) {
System.out.println("文件上传发生错误" + e1.getMessage());
}
Iterator it = items.iterator();
while (it.hasNext()) {
FileItem fileItem = (FileItem) it.next();
if (fileItem.isFormField()) {
uploadResult="0";
// String name = fileItem.getFieldName();
// if (fileItem.getFieldName().equals("username")){
// System.out.println("fileItem.toString() "+fileItem.toString()+" "+fileItem.getString());
// }
username=new String(fileItem.getString().getBytes(
"iso8859-1"), "gbk");
// System.out.println(fileItem.getFieldName()
// + " 00 "
// + fileItem.getName()
// + " 01 "
// + new String(fileItem.getString().getBytes(
// "iso8859-1"), "gbk"));
}