附件上传

public ModelAndView uploadAtt(HttpServletRequest request,HttpServletResponse response) throws FileUploadException, IOException, InterruptedException
	{
		String submitaction = "";
		String returnurl = "";
		String _taskName = "";
		String taskId = "";
		String _schemaId = "";
		String sessionUserName = "";
		String toDept = "";
		User user=(User)request.getSession().getAttribute("user");
		String docId = "";
		String uploadFiletype = "";	
		String uploadFilename = "";
		DiskFileUpload fu = new DiskFileUpload();
		fu.setSizeThreshold(4096);
		List fileItems = fu.parseRequest(request);
		Iterator itor = fileItems.iterator();
		byte[] uploadContent = null;
		while (itor.hasNext()) {
			FileItem item = (FileItem) itor.next();
			if (item.isFormField() == false) {// 如果是上传文件
				String uploadFilesuffix = ""; // 附件的后缀名
				uploadContent = item.get();

				uploadFiletype = item.getContentType();// 文件类型
				uploadFilename = item.getName();// 完整的文件名,例如:d:/test.doc
				if (!"".equals(uploadFilename)) {
					uploadFilesuffix = uploadFilename.substring(uploadFilename.lastIndexOf("."), uploadFilename.length());// 文件后缀,例如:doc		
				}
				uploadFilename=uploadFilename.substring(uploadFilename.lastIndexOf(File.separator)+1);
			} else {// 如果不是上传文件
				if ("docId".equals(item.getFieldName())) {
					docId = new String(item.getString().getBytes("ISO-8859-1"),"GBK");
				}
				if("returnurl".equals(item.getFieldName())){
					returnurl = new String(item.getString().getBytes("ISO-8859-1"),"UTF-8");
				}
				if("submitaction".equals(item.getFieldName())){
					submitaction = new String(item.getString().getBytes("ISO-8859-1"),"UTF-8");
				}
				if("nodeName".equals(item.getFieldName())){
					_taskName = new String(item.getString().getBytes("ISO-8859-1"),"UTF-8");
				}
				if("taskId".equals(item.getFieldName())){
					taskId = new String(item.getString().getBytes("ISO-8859-1"),"GBK");
				}
				if("schemaId".equals(item.getFieldName())){
					_schemaId = new String(item.getString().getBytes("ISO-8859-1"),"UTF-8");
				}
				if("signUserName".equals(item.getFieldName())){
					sessionUserName = new String(item.getString().getBytes("ISO-8859-1"),"UTF-8");
				}
				
			}
		}
		
	}


你可能感兴趣的:(java,附件上传)