Ajax在JQuery中的应用(get方法练习1)
来源:互联网 发布:织梦cms文档权限 编辑:程序博客网 时间:2024/05/21 14:06
index.html
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>test get()</title><script type="text/javascript" src="script/jquery-3.1.1.js"></script><script type="text/javascript"> $(function() { $("input:eq(2)").click(function(){ $.get("GetServlet", {'username':encodeURI(encodeURI($("#username").val())), 'password':encodeURI(encodeURI($("#password").val())) },function(data,textStatus){ $("#content").html(data); alert(textStatus); }); });});</script></head><body> <input type="text" name="username" id="username"/><br/> <input type="password" name="password" id="password"/><br/> <input type="button" value="登陆"/> <div id="content"></div></body></html>
GetServlet.java
package com.login;import java.io.IOException;import java.io.PrintWriter;import java.net.URLDecoder;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;@WebServlet("/GetServlet")public class GetServlet extends HttpServlet { private static final long serialVersionUID = 1L; public GetServlet() { super(); // TODO Auto-generated constructor stub } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); PrintWriter out=response.getWriter(); request.setCharacterEncoding("utf-8"); String username=URLDecoder.decode(URLDecoder.decode(request.getParameter("username"), "UTF-8"),"utf-8");//两次解码 String password=URLDecoder.decode(URLDecoder.decode(request.getParameter("password"), "UTF-8"),"utf-8"); if(username.equals("海哥")&&password.equals("haige")){ out.println("<p>欢迎"+username+"光临</p>"); } else{ out.println("<p>用户名或密码错误!"); } out.close(); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); }}
截图:
0 0
- Ajax在JQuery中的应用(get方法练习1)
- Ajax在JQuery中的应用(Get方法练习2)
- JQuery中ajax,get方法在asmx中的使用
- Ajax在jQuery中的应用
- ajax在jquery中的应用
- AJAX在jQuery中的应用
- jQuery ajax中的get()与post()方法
- Ajax在JQuery的运用(load方法练习)
- JQuery--Ajax--get方法
- jQuery ajax - get() 方法
- JQuery AJAX $.get()方法
- jQuery ajax - get() 方法
- JQuery 中的ajax的方法 ($.ajax,$.post.$get,$.jgetJSON)
- JQuery中ajax,get方法在ashx,aspx,asmx中的使用
- JQuery中ajax,get方法在ashx,aspx,asmx中的使用
- Ajax(Asynchronous JavaScript and XML)在JQuery中的应用
- JQuery、JSON、Ajax在Servlet中的应用
- JQuery、JSON、Ajax在Servlet中的应用
- fragment与Activity之间数据的传递
- Part 67 - Action selectors in mvc - ActionName AcceptVerbs
- 栈帧练习题
- 设置Android Studio导入类时不自动使用全限定名
- [生存志] 第32节 女娲造人类
- Ajax在JQuery中的应用(get方法练习1)
- 基于XUtil工具的多个文件下载显示总进度
- Linux周期性任务计划
- 【Hibernate】OpenSession和getCurrentSession的区别
- Part 69 - Action filters in mvc
- linux驱动开发:串口协议
- BBR: Bottleneck Bandwith and RTT Congestion Control Algorith For TCP
- oj第十一周训练——查闰年
- Part 68 - What is the use of NonAction attribute in mvc