<!DOCTYPE html>
<html>
<head>
<title>login.html</title>
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js">
</script>
<script type="text/javascript">
$(function() {
$("#login").click(function() {
$.ajax({ //no need to judge the browser type
type : "POST", //类型
url : "myServlet", //请求访问的servlet
dataType : "html",
data : {
}, //传递的参数
success : function(returnedData) { //成功返回的回调函数
}
});
});
});
</script>
</head>
<body>
<form>
<label>用户名</label> <input type="text" /> <br /> <label>密码</label> <input
type="text" />
<button type="button" id="login">登陆</button>
</form>
</body>
</html>
上边是html 页面,我想提交到 servlet 中,该怎么做呢
------解决思路----------------------
以前在学校里的时候这么弄过
上面加个标签<base href="/项目名/">
url:"直接写路径",
用的是springmvc servlet一样的吧
------解决思路----------------------
没有问题,ajax说:给我一个url,什么都访问给你看
------解决思路----------------------
楼主写的东西,貌似没得问题吧
------解决思路----------------------
可以的,路径写正确就行。url : '${pageContext.request.contextPath}/servlet/UserServlet?method='
------解决思路----------------------
你提交的数据都会经过过滤器,只要你配置了servlet过滤器,就能过滤到,ajax请求和request请求是一个道理,只是一个请求要转发,一个请求直接取响应数据,不会跳转页面