解决方法:
对于第三种情况我们直接request.getParameter来取参数值是取不到的
我们可以借用apache的上传组件来解决
用到jar包commons-fileupload-1.1.1.jar
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import
org.apache.commons.fileupload.servlet.ServletFileUpload;
/**
*获取各种类型表单的表单参数
*@paramrequest HttpServletRequest请求对像
* @paramparamName 参数名
*@return
*@throwsFileUploadException
*/
publicstatic String
getParameterValue(HttpServletRequest request,String paramName) throws
FileUploadException{
boolean
isMultipart = ServletFileUpload.isMultipartContent(request);
if(isMultipart==true){
FileItemFactory
factory = new DiskFileItemFactory();
ServletFileUpload
upload = new ServletFileUpload(factory);
List
fileItemList = upload.parseRequest(request);
if(fileItemList!=null){
for(Iterator itr=fileItemList.iterator();itr.hasNext();){
FileItem fileItem = (FileItem)itr.next();
if(fileItem.getFieldName().equalsIgnoreCase(paramName)){
return new
String(fileItem.getString().getBytes("ISO8859-1"))//中文转码
}
}
}
}else{
return new String(request.getParameter(paramName).getBytes("ISO8859-1"))//中文转码
}
return"";
}
|