软件测试中的一个ajax的经典测试用例
作者:网络转载 发布时间:[ 2012/10/25 11:06:12 ] 推荐标签:
软件测试中的一个ajax的经典测试用例
[1]写index.jsp文件
<%@ page contentType="text/html;charset=gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<script type="text/javascript">
var req;
function validate() {
var idField = document.getElementById("userid");
var url = "servlet/ValidateServlet?id=" + escape(idField.value);
if (window.XMLHttpRequest) {
alert("0");
req = new XMLHttpRequest();
}else if (window.ActiveXObject) {
alert("1");
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if(req){
req.open("GET", url, true);
req.onreadystatechange = callback;
req.send(null);
}
}
function callback() {
if (req.readyState == 4) {
if (req.status == 200) {
parseMessage();
// update the HTML DOM based on whether or not message is valid
}else{
alert ("Not able to retrieve description" + req.statusText);
}
}
}
function parseMessage() {
var message = req.responseXML.getElementsByTagName("message")[0];
var name = req.responseXML.getElementsByTagName("name")[0];
setMessage(message.firstChild.data,name.firstChild.data);
}
function setMessage(message,name) {
var userMessageElement = document.getElementById("userIdMessage");
userMessageElement.innerHTML = "<font color="red">" + message + " you "+name+"</font>";
}
</script>
<div id="userIdMessage"></div>
<input type="text"
size="20"
id="userid"
name="id"
onkeyup="validate();">
</body>
</html>
[2] 写servlet/ValidateServlet.java类
/*
* 创建日期 2005-8-3
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 项 - Java - 代码样式 - 代码模板
*/
package com;//com包需要自己创建.
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Administrator
*
* TODO 要更改此生成的类型注释的模板,请转至
* 窗口 - 项 - Java - 代码样式 - 代码模板
*/
public class ValidateServlet extends HttpServlet {
/**
* Constructor of the object.
*/
private ServletContext context;
private HashMap users = new HashMap();
public ValidateServlet() {
super();
}
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11