-
通过表单向服务端发起请求
-
通过链接向服务端发起请求
-
Ajax向服务端发起请求
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basepath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
out.println(basepath); // http://localhost:8080/BaseServlet/
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>index page</title>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
function fun() {
$.get("<%=path%>/StuServlet", {
"method" : "selectStu",
"user" : "tom"
}, function(data) {
alert(data);
});
}
</script>
</head>
<body>
<!-- 1. 通过表单向服务端发起请求 -->
<form action="<%=path%>/StuServlet?method=addStu" method="post">
<button>form表单post提交</button>
</form>
<br />
<!-- 2. 通过链接向服务端发起请求 -->
<a href="<%=path%>/StuServlet?method=deleteStu">超链接</a>
<br />
<!-- 3. Ajax向服务端发起请求 -->
<button onclick="fun()">Ajax方式</button>
</body>
</html>
网友评论