软件测试中的一个ajax的经典测试用例
作者:网络转载 发布时间:[ 2012/10/25 11:06:12 ] 推荐标签:
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @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 oclearcase/" target="_blank" >ccurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
String targetId = request.getParameter("id");
System.out.println(targetId.trim());
if ((targetId != null) && users.containsKey(targetId.trim())) {
response.getWriter().write("<info><message>welcome</message><name>sdl</name></info>");
} else {
response.getWriter().write("<info><message>kill</message><name>bush</name></info>");
System.out.print("invalid");
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init(ServletConfig config) throws ServletException {
this.context = config.getServletContext();
users.put("greg","account data");
users.put("duke","account data");
}
}
[3]写web.xml文件<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee "
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>ValidateServlet</servlet-name>
<servlet-class>com.ValidateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ValidateServlet</servlet-name>
<url-pattern>/servlet/ValidateServlet</url-pattern>
</servlet-mapping>
</web-app>
[4]说明:
你可以在IE或FireFox里测试,在文本输入框里输入,当按键抬起,会在层中显示”kill you bush”。其中index.htm中的styles.css只是美化页面,没有列出来源代码。如果在servlet向客户端输出中文,需要编码转换。
[多此一举]
你需要了解tomcat工程。熟悉xmlHttpRequest,java servlet,html等知识。
相关推荐
更新发布
功能测试和接口测试的区别
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