防火墙原理详解之iptables的使用
2014-10-29 23:52
357 查看
1、在HTML中,有这样一个表单:
当然,要想在HTML中使用Js功能,必须在<head/>中加入
2、然后在ajax.js文件中加入如下代码
解释如下:
1)、"#searchform input[@name='query']";的意思是: 选择id为searchform其下的(name属性值为’query’的)input标签
2)、$(“”).val()意为要得到(“”)所选中属性的值;
3)、在$.post()中,第一项参数是指定目标servlet,即要把本post请求发给的那个servlet。
第二项是本post请求所携带的数据;“:”前的为key或者name,后为value;
第三项是回调函数,其内若有形参,则表示要对从servlet返回的值进行处理,这里的callback的功能是将JSON对象json转换成了JS对象userlist,然后将JS对象传入函数userList
3、post请求携带了名为query的参数去了后台,在servlet中进行处理:
<form method="post" name="searchform" id="searchform" method="/sek.go"> <input name="query" value="" type="text" id="query" /> <input type=”submit” value="查询"></input> </form>
当然,要想在HTML中使用Js功能,必须在<head/>中加入
<script type="text/javascript"src="/style/js/ajax.js"></script>
2、然后在ajax.js文件中加入如下代码
function userSearch(){ var query = $("#searchform input[@name='query']").val(); $.post("/userSearch.htm", { query: query } ,function callback(json){ var userlist = $.parseJSON(json); userList(userlist); }); }
解释如下:
1)、"#searchform input[@name='query']";的意思是: 选择id为searchform其下的(name属性值为’query’的)input标签
2)、$(“”).val()意为要得到(“”)所选中属性的值;
3)、在$.post()中,第一项参数是指定目标servlet,即要把本post请求发给的那个servlet。
第二项是本post请求所携带的数据;“:”前的为key或者name,后为value;
第三项是回调函数,其内若有形参,则表示要对从servlet返回的值进行处理,这里的callback的功能是将JSON对象json转换成了JS对象userlist,然后将JS对象传入函数userList
3、post请求携带了名为query的参数去了后台,在servlet中进行处理:
//从名为"query"能的参数中取出post带过来的数据 String query = request.getParameter("query"); if (query != null && !query.isEmpty() && !query.trim().equalsIgnoreCase("")) { //如果"query"的值不为空,就用'query'为参数构建HQL语句 String hql = "from TUser as user where user.userName like '"+ query + "%'"; //到库表TUser中进行查询,并得到一个表结构 List list = weilav3TUserDAO.getListByHQL(hql); if (list != null && !list.isEmpty()) { //若list不为空,则将其转换成JSON对象,并存入jsonArray中 JSONArray jsonArray = JSONArray.fromObject(list); //下面就是把存有查询结果的JSON对象返给页面 response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); out.println(jsonArray); …… }else {……}
相关文章推荐
- 企业常用防火墙iptables相关原理详解
- linux防火墙iptables原理及使用
- linux下防火墙iptables原理及使用
- 配置防火墙,开启80端口、3306端口 & iptables 使用详解
- iptables防火墙原理详解
- iptables防火墙详解(四)使用layer7添加应用层过滤功能
- iptables防火墙原理详解+mysql pt工具
- linux下防火墙iptables原理及使用
- iptables防火墙原理详解
- 配置防火墙,开启80端口、3306端口 & iptables 使用详解
- iptables防火墙原理详解
- 配置防火墙,开启80端口、3306端口 & iptables 使用详解
- iptables防火墙原理详解
- linux下防火墙iptables原理及使用
- iptables防火墙原理详解
- linux下防火墙iptables原理及使用
- Linux iptables防火墙原理详解
- 6--企业常用防火墙iptables相关原理详解
- 配置防火墙,开启80端口、3306端口 & iptables 使用详解
- linux下防火墙iptables原理及使用