1.Ajax: 不刷新整个页面,只刷新局部
1.1无刷新的好处:
1.1.1 提供连续的用户体验
1.1.2提供类似C/S的交互效果, *** 作更方面
2.常用属性:
2.1onreadystatechange:指定回调函数 readystate: XMLHttpRequest的状态信息
2.2status:HTTP的状态码
2.3 responseText:获得响应的文本内容
2.4responseXML:获得响应的XML文档对象
3.使用Ajax:
技术实现异步交互
创建XMLHttpRequest对象
通过 XMLHttpRequest对象设置请求信息
向服务器发送请求 创建回调函数,根据响应状态动态更新页面
代码块
登录login
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
Insert title here
package com.zking.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zking.dao.T277Dao;
import com.zking.entity.T277;
/**
* Servlet implementation class LoginServlet
*/
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("来了 老弟");
//接收数据
String uname = request.getParameter("uname");
String upwd = request.getParameter("upwd");
String uinfo = request.getParameter("uinfo");
System.out.println("uname:"+uname);
System.out.println("upwd:"+upwd);
request.setCharacterEncoding("utf-8");
//获取响应的 输出流
PrintWriter out = response.getWriter();
T277Dao dd = new T277Dao();
ArrayList tt = dd.getAll();
int c = 0;
for (int j = 0; j < tt.size(); j++) {
if(tt.get(j).getUname().equals(uname) && tt.get(j).getUpwd().equals(upwd)) {
c=1;
break;
}else {
c=2;
}
}
if(c==1) {
out.print("ok");
}else {
out.print("no");
}
out.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)