jQuery简单例子
?刚开始学习JQuery,也可以说是笔记吧,Jquery简化大量JS工作。今天我们来做一个类似登录功能;
我们来看看Client的代码
<script type="text/javascript" src="jquery/jquery.js"></script> </head> <script type="text/javascript"> function check(){ var queryString={name:encodeURI($("#name").val())}; // $.get("servlet/check",queryString,function(data){//$("#ok").html(decodeURI(data));//});//$.post("servlet/check",queryString,function(data){$("#ok").html(decodeURI(data));}); } </script> <body> name: <input type="text" id="name" onblur="check();"><div id="ok"></div> <input type="button" value="go" onclick="starta();">
?Server代码
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {String name=request.getParameter("name").toString();//response.setContentType("text/xml");把这个注释去掉就有危险PrintWriter out = response.getWriter();if(name.equalsIgnoreCase("nic")){out.println(" <p>用户已存在");out.println("</p>");}else{out.println(" <p>"+request.getParameter("name"));out.println("</p>");}out.flush();out.close();}/** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request,response);}
?web.xml
<servlet> <servlet-name>check</servlet-name> <servlet-class>check</servlet-class> </servlet> <servlet-mapping> <servlet-name>check</servlet-name> <url-pattern>/servlet/check</url-pattern> </servlet-mapping>
?
做一篇试试吧!!