- 浏览: 175260 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (321)
- eclipse (4)
- idea (2)
- Html (8)
- Css (14)
- Javascript (8)
- Jquery (6)
- Ajax Json (4)
- Bootstrap (0)
- EasyUI (0)
- Layui (0)
- 数据结构 (0)
- Java (46)
- DesPattern (24)
- Algorithm (2)
- Jdbc (8)
- Jsp servlet (13)
- Struts2 (17)
- Hibernate (11)
- Spring (5)
- S2SH (1)
- SpringMVC (4)
- SpringBoot (11)
- WebService CXF (4)
- Poi (2)
- JFreeChart (0)
- Shiro (6)
- Lucene (5)
- ElasticSearch (0)
- JMS ActiveMQ (3)
- HttpClient (5)
- Activiti (0)
- SpringCloud (11)
- Dubbo (6)
- Docker (0)
- MySQL (27)
- Oracle (18)
- Redis (5)
- Mybatis (11)
- SSM (1)
- CentOS (10)
- Ant (2)
- Maven (4)
- Log4j (7)
- XML (5)
最新评论
1. ajax验证用户名
2. ajax二级联动
2. ajax二级联动
GetAjaxInfoServlet.java package com.andrew.web; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class GetAjaxInfoServlet extends HttpServlet{ private static final long serialVersionUID = 1L; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); String action=request.getParameter("action"); if("checkUserName".equals(action)){ this.checkUserName(request, response); }else if("ejld".equals(action)){ this.ejld(request, response); } } private void checkUserName(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out=response.getWriter(); String userName=request.getParameter("userName"); JSONObject resultJson=new JSONObject(); if("jack".equals(userName)){ resultJson.put("exist", true); }else{ resultJson.put("exist", false); } out.println(resultJson); out.flush(); out.close(); } private void ejld(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out=response.getWriter(); String shengId=request.getParameter("shengId"); JSONObject resultJson=new JSONObject(); JSONArray jsonArray=new JSONArray(); JSONObject temp=null; switch(Integer.parseInt(shengId)){ case 1:{ temp=new JSONObject();temp.put("id", 1);temp.put("text", "南京");jsonArray.add(temp); temp=new JSONObject();temp.put("id", 2);temp.put("text", "南通");jsonArray.add(temp); temp=new JSONObject();temp.put("id", 3);temp.put("text", "泰兴");jsonArray.add(temp); break; } case 2:{ temp=new JSONObject();temp.put("id", 4);temp.put("text", "济南");jsonArray.add(temp); temp=new JSONObject();temp.put("id", 5);temp.put("text", "烟台");jsonArray.add(temp); temp=new JSONObject();temp.put("id", 6);temp.put("text", "蓬莱");jsonArray.add(temp); break; } case 3:{ temp=new JSONObject();temp.put("id", 7);temp.put("text", "杭州");jsonArray.add(temp); temp=new JSONObject();temp.put("id", 8);temp.put("text", "宁波");jsonArray.add(temp); temp=new JSONObject();temp.put("id", 9);temp.put("text", "温州");jsonArray.add(temp); break; } } resultJson.put("rows", jsonArray); out.println(resultJson); out.flush(); out.close(); } } web.xml <servlet> <servlet-name>getAjaxInfoServlet</servlet-name> <servlet-class>com.andrew.web.GetAjaxInfoServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>getAjaxInfoServlet</servlet-name> <url-pattern>/getAjaxInfo</url-pattern> </servlet-mapping> checkUserName.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript"> function checkUserName(){ var userName=document.getElementById("userName").value; var xmlHttp; if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); }else{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4 && xmlHttp.status==200){ alert(xmlHttp.responseText); var dataObj=eval("("+xmlHttp.responseText+")"); if(dataObj.exist){ document.getElementById("tip").innerHTML="<img src='no.png'/> 该用户名已经存在"; }else{ document.getElementById("tip").innerHTML="<img src='ok.png'/> 该用户名可用"; } } }; xmlHttp.open("get", "getAjaxInfo?action=checkUserName&userName="+userName, true); xmlHttp.send(); } </script> </head> <body> <table> <tr> <th>用户注册</th> </tr> <tr> <td>用户名:</td> <td><input type="text" id="userName" name="userName" onblur="checkUserName()"/> <font id="tip"></font></td> </tr> <tr> <td>密码:</td> <td><input type="text" id="password" name="password"/></td> </tr> <tr> <td>确认密码:</td> <td><input type="text" id="password2" name="password2"/></td> </tr> <tr> <td><input type="submit" value="注册"/></td> <td><input type="button" value="重置"/></td> </tr> </table> </body> </html> ejld.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript"> function checkUserName(){ var userName=document.getElementById("userName").value; var xmlHttp; if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); }else{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4 && xmlHttp.status==200){ alert(xmlHttp.responseText); var dataObj=eval("("+xmlHttp.responseText+")"); if(dataObj.exist){ document.getElementById("tip").innerHTML="<img src='no.png'/> 该用户名已经存在"; }else{ document.getElementById("tip").innerHTML="<img src='ok.png'/> 该用户名可用"; } } }; xmlHttp.open("get", "getAjaxInfo?action=checkUserName&userName="+userName, true); xmlHttp.send(); } </script> </head> <body> <table> <tr> <th>用户注册</th> </tr> <tr> <td>用户名:</td> <td><input type="text" id="userName" name="userName" onblur="checkUserName()"/> <font id="tip"></font></td> </tr> <tr> <td>密码:</td> <td><input type="text" id="password" name="password"/></td> </tr> <tr> <td>确认密码:</td> <td><input type="text" id="password2" name="password2"/></td> </tr> <tr> <td><input type="submit" value="注册"/></td> <td><input type="button" value="重置"/></td> </tr> </table> </body> </html> http://localhost:8080/HeadFirstAjaxJsonChap04/ejld.jsp http://localhost:8080/HeadFirstAjaxJsonChap04/checkUserName.jsp 该用户名可用
相关推荐
Ajax 实例,Ajax 实例,Ajax 实例Ajax 实例,Ajax 实例,Ajax 实例,Ajax 实例
ajax 实例实例实例ajax 实例实例实例ajax 实例实例实例ajax 实例实例实例ajax 实例实例实例ajax 实例实例实例ajax 实例实例实例ajax 实例实例实例
ajax实例ajax实例ajax实例ajax实例ajax实例ajax实例ajax实例ajax实例ajax实例ajax实例ajax实例ajax实例ajax实例ajax实例
Ajax实例演示Ajax实例演示Ajax实例演示Ajax实例演示
AJAX实例大全(有演示).这本书还不错,推荐给大家看看.
Ajax实例,实用性强,练习异步请求。Ajax实例,实用性强,练习异步请求。Ajax实例,实用性强,练习异步请求。Ajax实例,实用性强,练习异步请求
《ajax实例demo》《ajax实例demo》《ajax实例demo》《ajax实例demo》
不错的例子不错的例子不错的例子不错的例子不错的例子不错的例子不错的例子不错的例子不错的例子
thinkphp ajax实例
Ajax实例 超简单!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
spring,hibernate,struts1,ajax 实例
datatables使用ajax的实例,下载文件,eclipse引入该项目即可运行,看到结果。
AJAX实例应用 有20多个实例
简单代码实现ASP+AJAX+ACCESS无刷新请求功能实现,实用新手了解
ajax实例.zip 含有大量的ajax实例,供学习ajax的同志们参考
Ajax实例 Ajax特效+mySQL数据库
ajax教程 ajax实例,手把手教你ajax应用。
ajax实例大全,包过很多使用的方面,局部验证,无刷新回复,灯罩效果等等
jquery ajax实例点击按钮触发Ajax loading jquery ajax实例点击按钮触发Ajax loading jquery ajax实例点击按钮触发Ajax loading