jquery访问servlet并返回数据到页面的方法?
假设:
1、你的页面在Web-Root下,内容为:
2、你的servlet为: HelloWorldServlet.java 映射路径为 servlet/helloWorldServlet 步骤: 1、引入jquery-1.6.4.min.js 2、编写id为userName的输入框的点击触发函数: $("#userName").keyup(function(){ $.ajax({ type: "post", url: "servlet/helloWorldServlet?userName="+$(this).val(), dataType: "json", success: function(data){ $("#showMsg").html(data.msg);//修改id为showMsg标签的html }, error: function(){ alert("请求出错"); } }) })
3、后台处理接收到的内容: request.setCharactorEncoding("utf-8"); String userName = request.getParameter("userName"); response.setCharactorEncoding("utf-8"); PringWriter out = response.getWriter(); out.print("{"msg":"你好~~"+userName+"!"}"); 注意事项: 1、这里的编码统一为utf-8 2、请求路径servlet/helloWorldServlet为相对路径,因此你的页面必须在项目的Web-Root下(也就是默认的web文件夹下,名字可能因项目配置不同而改变) 3、没了,记得给分哦,打字很辛苦的~
html怎么快速引入jQuery文件?
具体的代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="/js/jquery/jquery-3.2.1.js"></script>
</head>
<body>
</body>
</html>
或者<script src="JQuery路径"></script>
扩展资料
HTML是一种规范,一种标准,它通过标记符号来标记要显示的网页中的各个部分。网页文件本身是一种文本文件,通过在文本文件中添加标记符,可以告诉浏览器如何显示其中的内容(如:文字如何处理,画面如何安排,图片如何显示等)。
浏览器按顺序阅读网页文件,然后根据标记符解释和显示其标记的内容,对书写出错的标记将不指出其错误,且不停止其解释执行过程,编制者只能通过显示效果来分析出错原因和出错部位。但需要注意的是,对于不同的浏览器,对同一标记符可能会有不完全相同的解释,因而可能会有不同的显示效果。
还没有评论,来说两句吧...