servlet从客户端向服务端发送请求调用功能的几种方式
1:通过表单向服务端发起请求 (action)
2:通过链接向服务端发起请求
3:通过ajax向服务端发起请求
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="js/jquery-1.11.3.min.js" type="text/javascript"></script>--这里添加ajax的东西
</head>
<body>
<form action="/BaseServlet/ServletDemo01?method=addStu" method="post">--1,通过页面action 点提交按钮触发servlet
用户<input type="text" name="username"/><br/>
<button>提交</button>
</form>
<br/>
<a href="/BaseServlet/ServletDemo01?method=delStu">删除学生</a><br/>--2,通过点‘删除学生’,链接触发servlet
<button onclick="fn()">按钮</button> --3,通过按钮ajax触发servlet
<script>
function fn(){
$.post("/BaseServlet/ServletDemo01",{
"method":"checkStu","user":"tom"},function(data){
alert(data);
});
}
</script>
</body>
</html>
通过表单的请求触发到传到servlet中:
public class ServletDemo01 extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException