jsp文件上传自定义按钮字体

//通过input标签type="file"实现文件上传



//form表单方式实现文件上传
导入问卷
//匹配form表单方式的文件上传
/**   
	 * @Title: analysis   
	 * @Description: TODO(解析调查问卷导入excel)      
	 * @return: void        
	 * @author: Lby
	 * @date: 2019年8月15日
	 */ 
	@RequestMapping(value = {"/analysis"})
	public String analysis(HttpServletRequest request, HttpServletResponse response,@RequestParam(value="file") MultipartFile file) {
		//将excel中的所有问题全部插入到List中
		List> messageBatchList = new ArrayList>();
		ModelAndView modelAndView = new ModelAndView("/edit");
		String originalFileName = file.getOriginalFilename();
		String fileType = originalFileName.substring(originalFileName.lastIndexOf("."));
        //读取excel文件
        InputStream is = null;
        String questionnaireId = request.getParameter("questionnaireId");
		Integer voteId = Integer.valueOf(questionnaireId);
		Integer siteId = this.getMySite().getId(); 
        //获取工作薄
        Workbook wb = null;
        //定义问题类型
        String question_type = null;
        //题目
        String title = null;
        try {
            is = file.getInputStream();
            if (fileType.equals(".xls")) {
                wb = new HSSFWorkbook(is);
            } else if (fileType.equals(".xlsx")) {
                wb = new XSSFWorkbook(is);
            }
            //读取第一个工作页sheet
            Sheet sheet = wb.getSheetAt(0);
            //遍历sheet页中的行信息
            for (Row row : sheet) {
            	System.out.println("第"+row.getRowNum()+"行");
            	//从第二行开始
            	if(row.getRowNum() > 0) {
            		Map map = new HashMap();
            		Map message = null;
            		map.put("voteId", voteId);
                	map.put("siteId", siteId);
                	QuestionDto questionDto = new QuestionDto();
                    for (Cell cell : row) {
	                	cell.setCellType(Cell.CELL_TYPE_STRING);
	                	int cellNum = cell.getColumnIndex();
                    	//获取问题类型
                    	if(cellNum == 0) {
                    		question_type = cell.getStringCellValue();
                    		map.put("question_type", question_type == null ? "":question_type);
                    		//题目
                    	}else if(cellNum == 1 ){
                    		title = cell.getStringCellValue();
                    		map.put("title", title == null ? "" : title);
                    		//问题
                    	}else if(cellNum == 2) {
                    		String cellValue = cell.getStringCellValue();
                    		List questionOptionDtoList = new ArrayList();
                    		if(cellValue != null) {
                    			String[] options= cell.getStringCellValue().split("#");
                        		for(String option:options) {
                        			QuestionOptionDto questionOptionDto = new QuestionOptionDto();
                        			questionOptionDto.setTitle(option);
                        			questionOptionDtoList.add(questionOptionDto);
                        		}
                        		questionDto.setOptionList(questionOptionDtoList);
                    		}
                    	}
                    }
                    if(questionDto.getOptionList() == null ) {
                    	List questionOptionDtoList = new ArrayList();
						if ("多行填空题".equals(question_type)) {
							QuestionOptionDto questionOptionDto = new QuestionOptionDto();
							questionOptionDto.setTitle("");
	            			questionOptionDtoList.add(questionOptionDto);
	            			questionDto.setOptionList(questionOptionDtoList);
						}else{
							for(int i = 1 ; i <= 2; i++) {
								QuestionOptionDto questionOptionDto = new QuestionOptionDto();
								questionOptionDto.setTitle("选项"+i);
		            			questionOptionDtoList.add(questionOptionDto);
							}
							questionDto.setOptionList(questionOptionDtoList);
						}
                    }
//                  将选项信息的List插入Map
                    map.put("option_list", questionDto.getOptionList() == null ? "" : questionDto.getOptionList());
                    try {
    					messageBatchList.add(map);
    				} catch (Exception e) {
    					logger.error("调查问卷导入失败", e);
    					e.printStackTrace();
    				}
            	}
            }
            try {
				questionService.saveQuestionBatch(messageBatchList);
			} catch (Exception e) {
				logger.error("调查问卷导入失败", e);
				e.printStackTrace();
			}
        } catch (IOException e) {
        	logger.error("调查问卷导入失败", e);
			e.printStackTrace();
        } 
        return "forward:list";
	}

 

你可能感兴趣的:(jsp)