第一步:用IDEA建一个WEB SERVLET工程
第二步:写idex.jsp代码:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>$Title$</title> <script type="text/javascript"> var url = "fetch"; fetch(url,{ method:"post", headers:{ "Content-type":"application/x-www-form-urlencoded" }, body:"name=luwenjing&age=22" }) .then(function (response){ if (response.status == 200){ return response; } }) .then(function (data) { return data.text(); }) .then(function(text){ console.log("请求成功,响应数据为:",text); }) .catch(function(err){ console.log("Fetch错误:"+err); }); </script> </head> <body> <h1