前端-fetch-后台:整理笔记

前端页面:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
<div class="container">
	<form action="" id="form1" method="get">
	     <label for="name">Name</label>
		 <input type="text" name="name" placeholder="name" value="name">
		 <br>
		 <label for="sex">sex</label>
		 <input type="radio" name="sex" value="男"><input type="radio" name="sex" value="女"><br>
		 <label for="addr">Address</label>
		 <input type="text" name="addr" placeholder="addr">
		 <input type="button" value="submit" onclick="tijiao()">
   </form>
</div>
<script>
function tijiao(){
     var fd=new FormData(document.getElementById("form1"));
     fetch('/change/yu?'+encodeURI(Array.from
     (fd.entries()).map(el=>el.join("=")).join("&"))
     ).then(function (aaa){return        
     aaa.text();}).then(function(bb){console.log(bb);});
}

</script>
</body>
</html>

部署到tomacat中:
在文件D:\apache-tomcat-7.0.92\conf\Catalina\localhost\yu.xml(
也就是配置tomacat的xml)
代码如下

<Context docBase="C://Users/mcfeng/Desktop/html"></Context>

复制html上一层的目录;
启动服务器:
访问地址:
localhost:8080/yu(配置xml的名字)/demo.html(前端名字);
提交表单后
fetch: 跳转到localhost:8080/change/yu(tomacat-path/url-pattern);
解决编码(有点复杂):
只有初步的解决方案:

 String a=request.getParameter("name");
	     System.out.println(new String(a.getBytes("ISO-8859-1"),"utf-8"));

在这里插入图片描述
有点麻烦;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值