首页 - Ajax专区 - 实例应用

一个ajax的经典测试用例 (jsp)

发布时间: 2007-03-19 12:35    作者: 未知    来源: 未知    浏览:    评论

上一页 1 2 下一页

* @throws ServletException if an error occurred
* @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中的http://www.okajax.com/info/example/styles.css只是美化页面,没有列出来源代码。如果在servlet向客户端输出中文,需要编码转换。

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=453440

上一页 1 2 下一页

TAG

Smile Big Smile Surprise Stick out tongue Wink Sad Tongue Tied Indifferent Crying Embarrassed Cool Angry Angel Devil [8-|] [:#] [:-*] [:^)] [<:o)] [|-)] Yes Beer Left Hug Music Star Time Snail Pizza Automobile Umbrella Computer Storm [mo] [8o|] [^o)] [+o(] [*-)] [8-)] Coffee No Drinks [Z] Right Hug Cake Broken Heart Gift Wilted Flower Movie Dog Idea Sleep Email Travel Paradise
呢称:

加粗 斜体 下划线 链接 图片 代码 邮件地址 引用 列表

最多只能输入100个字符