spring boot项目访问jsp页面变成下载

<!--jsp支持-->
<!-- servlet 依赖. -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <scope>provided</scope>
</dependency>
<!-- tomcat 的支持.-->
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>tomcat-jsp-api</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

spring boot项目访问jsp出现cannot be resolved in either web.xml or the jar files deployed with this application错误,原因是c标签jstl的maven坐标未正确导入,可以先暂时删除jsp页面的c标签

spring boot项目访问jsp出现java.lang.ClassNotFoundException: org.apache.jsp.index_jsp错误,原因也是c标签jstl的maven坐标未正确导入,可以先暂时删除jsp页面的c标签

spring boot项目中mybatis的mapper找不到,Consider defining a bean of type ‘tang.poi_test.CarinfoMapper’ in your configuration,原因在于spring boot启动类上要加@MapperScan注解。
@MapperScan(“tang.poi_test”)

spring mvc项目接收数组参数解决办法:
后台:
Carinfo是实体类。

@ResponseBody
	@RequestMapping("/save")
	public List<Carinfo> save(HttpServletRequest request,@RequestBody List<Carinfo> carinfos) {
		for (Carinfo carinfo : carinfos) {
			myService.insert(carinfo);
		}
		return carinfos;
	}

前端:

function save(){
	var newrows=$(".newrow");
	var jsondata=new Array();
	newrows.each(function(){
		var inputs=$(this).find("input");
		var rowdata={};
		for(var i=0;i<inputs.length;i++){
			var name=$(inputs[i]).attr("name");
			var value=inputs[i].value;
			rowdata[name]=value;
		}
		jsondata.push(rowdata);
	});
	$.ajax({
		type : "post",
		data : JSON.stringify(jsondata),
		url : "save",
		contentType : "application/json; charset=utf8",
		//contentType : "application/x-www-form-urlencoded; charset=utf8",
		dateType : "json",
		success : function(data) {
			alert("保存成功");
		},
		error : function(err) {
			alert("网络异常或系统错误,请稍后重试!");
		}
	});
}

spring mvc文件上传:
后台:

@ResponseBody
	@RequestMapping("/upload")
	public JsonResult upload(HttpServletRequest request,@RequestParam("uploadFile") MultipartFile file) {
		JsonResult result=new JsonResult();
		result.setCode("400");
		if (!HttpUtils.isEmptyFile(file)) {
			if (!HttpUtils.isAllowUploadFileExt(file.getOriginalFilename(), "xlsx")) {
				
				result.setMsg("文件格式错误,只允许" + HttpUtils.extMap.get("xlsx") + "格式");
			}else if (file.getSize() > HttpUtils.fileSize1mb) {// 文件上传大小
				result.setMsg("文件最大不得超过1MB");
			}else {
				try {
					Workbook workbook = WorkbookFactory.create(file.getInputStream());
					
					String path = HttpUtils.getPath(request, "error", file.getOriginalFilename());
					return taskHandle(request,workbook, file, path);
//					
//					String path = HttpUtils.uploadFile(request, file, "excel");
//					String basePath = HttpUtils.getBasePath(request);
//					String fullPath = basePath + path;
//					result.setCode("200");
//					result.setMsg("上传成功");
//					result.setData(fullPath);
//					System.out.println("上传成功>>>>>>>>>>>>>>>>>>>"+fullPath);
				} catch (Exception e) {
					e.printStackTrace();
					result.setMsg("上传文件发生错误");
				}
			}
		}else{
			result.setMsg("上传的文件为空");
		}
		return result;
	}

前端:
注释部分是非ajax提交,是能用的。

function upload(){
	var formEle=document.getElementById("dataForm");
	//formEle.method="post";
	//formEle.enctype="multipart/form-data";
	//formEle.action="upload";
	//formEle.submit();
	var form = new FormData(formEle);
	$.ajax({
		type : "post",
		data : form,
		url : "upload",
		cache: false,
		processData: false,
		contentType: false,
		dateType : "json",
		success : function(data) {
			if(data){
				if(data.code=="200"){
					alert(data.data);
				}else{
					alert(data.msg);
				}
			}else{
				alert("网络异常或系统错误,请稍后重试!");
			}
		},
		error : function(err) {
			alert("网络异常或系统错误,请稍后重试!");
		}
	});
}

前端html:
将input file放入dataForm这个form中即可。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值