- 浏览: 303482 次
- 性别:
- 来自: 江阴
文章分类
最新评论
例子来源:《Ajax 基础教程》 金灵 等译 这本书非常不错
postingXML.html
PostingXMLExample.java
postingXML.html
<html> <head> <title></title> <script type="text/javascript"> var xmlHttp; function createXMLHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } } function createXML() { var xml = "<pets>"; var options = document.getElementById("petTypes").childNodes; var option = null; for(var i = 0; i < options.length; i++) { option = options[i]; if(option.selected) { xml = xml + "<type>" + option.value + "<\/type>"; } } xml = xml + "<\/pets>"; return xml; } function sendPetTypes() { createXMLHttpRequest(); var xml = createXML(); var url = "PostingXMLExample?timeStamp=" + new Date().getTime(); xmlHttp.open("POST", url, true); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); xmlHttp.send(xml); } function handleStateChange() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { parseResults(); } } } function parseResults() { var responseDiv = document.getElementById("serverResponse"); if (responseDiv.hasChildNodes()) { responseDiv.removeChild(responseDiv.childNodes[0]); } var responseText = document.createTextNode(xmlHttp.responseText); responseDiv.appendChild(responseText); } </script> </head> <body> <h1>Select the types of pets in your home: </h1> <form action="#" > <select id="petTypes" size="6" multiple="true"> <option value="cats">cats</option> <option value="dogs">dogs</option> <option value="fish">fish</option> <option value="birds">birds</option> <option value="hamsters">hamsters</option> <option value="rabbits">rabbits</option> </select> <br /><br /> <input type="button" value="submit Pets" onclick="sendPetTypes();" /> <h2>Server Response:</h2> <div id="serverResponse"></div> </form> </body> </html>
PostingXMLExample.java
package ajaxbook.chap3; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class PostingXMLExample extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String xml = readXMLFromRequestBody(request); Document xmlDoc = null; try { xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new ByteArrayInputStream(xml.getBytes())); } catch(ParserConfigurationException e) { System.out.println("ParserConfigurationException: " + e); } catch(SAXException e) { System.out.println("SAXException: " + e); } NodeList selectedPetTypes = xmlDoc.getElementsByTagName("type"); String type = null; String responseText = "selected Pets: "; for(int i = 0; i < selectedPetTypes.getLength(); i++) { type = selectedPetTypes.item(i).getFirstChild().getNodeValue(); responseText = responseText + " " + type; } response.setContentType("text/xml"); response.getWriter().print(responseText); } private String readXMLFromRequestBody(HttpServletRequest request) { StringBuffer xml = new StringBuffer(); String line = null; try { BufferedReader reader = request.getReader(); while((line = reader.readLine()) != null) { xml.append(line); } } catch(Exception e) { System.out.println("Error reading XML: " + e.toString()); } return xml.toString(); } }
发表评论
-
校验输入的日期是否在当前日期一个月以内
2013-07-15 16:15 981<html> <head> ... -
两个页面之间的跳转
2012-12-05 09:54 1256从a.html页面跳转到b.html页面, a.html ... -
javascript 选中select中的某个元素(初学者)
2012-09-17 21:24 988<html> <head> ... -
用javascrip实现两个select互相传递值
2009-07-19 20:18 1284<html> <head> ... -
dynamicLists.html
2009-03-25 23:18 781例子来源:《Ajax 基础教程》 金灵 等译 这本书非常不错 ... -
validation.html
2009-03-25 23:15 719例子来源:《Ajax 基础教程》 金灵 等译 这本书非常不错 ... -
readingResponseHeaders.html
2009-03-25 23:13 948例子来源:《Ajax 基础教程》 金灵 等译 这本书非常不错 ... -
parsexml.html
2009-03-25 23:08 940例子来源:《Ajax 基础教程》 金灵 等译 这本书非常不错 ... -
innerHTML.html
2009-03-25 23:06 1099例子来源:《Ajax 基础教程》 金灵 等译 这本书非常不错 ... -
getAndPostExample.html
2009-03-25 23:04 1079例子来源:《Ajax 基础教程》 金灵 等译 这本书非常不错 ... -
动态获得xml格式的数据 dynamicContent.html
2009-03-25 23:02 1226dynamicContent.html 例子来源:《Ajax ... -
json2.js json.jar
2009-03-25 22:56 11284json.jar 这个东西真难找,提供给大家下载。 并且抄一 ... -
用javascript实现下拉菜单互动
2007-07-13 17:37 1762js 代码 <html> ... -
在html页面中屏蔽鼠标右键
2007-06-26 10:14 2554屏蔽鼠标右键 oncontextmenu=" ... -
javascript事件列表解说(转载) 选择自 iuhxq 的 Blog
2007-05-18 10:15 1268java ... -
菜单选择改变显示
2006-11-08 14:54 1227<html> <head> ... -
JS判断页面上的单选按钮是否选中
2006-11-07 16:51 14269<html> <head> ... -
用正则表达式控制输入格式
2006-11-02 15:14 1838<html> <head>< ... -
html页面进来要它执行一段JS的方法
2006-11-02 10:26 1974方法一: <html> <head& ...
相关推荐
面向多场景应用的光网络通感一体化架构和关键技术方案研究
该项目是基于Vue框架的Digital Twin开发设计源码,由38个文件组成,涉及TypeScript、JavaScript、Vue、CSS、HTML等多种编程语言,包括9个TypeScript文件、6个JavaScript文件、5个JSON文件、5个Vue文件、3个SVG文件、2个Markdown文件、2个WebAssembly文件、1个Git忽略文件、1个HTML文件和1个CSS文件。该源码旨在提供大学生在线学术交流的平台,助力学术创新与协作。
该项目是一款基于Java和C++技术的易涂鸦设计平台源码,包含487个文件,其中Java源文件226个,PNG图片文件135个,XML配置文件88个,其他类型文件包括brush文件7个,gradle文件4个,jpg文件4个,gitignore文件3个,properties文件3个,md文件2个,txt文件2个。该平台专注于涂鸦功能,为用户提供便捷的设计与绘图体验。
该项目是一款基于HTML、CSS和JavaScript的多人在线知识交流平台博客,设计源码包含451个文件,其中包括149个Java文件、89个JavaScript文件、60个CSS文件、42个Class文件、23个PNG图片文件、20个XML文件、17个HTML文件、12个JPG文件、6个JSON文件、5个Map文件,旨在为用户提供一个互动的知识分享与交流空间。
开关电源工作原理及电路图技术资料开发设计用的重要资料.zip
该项目是一款基于Plpgsql与Java开发的学生管理系统源码,总计包含190个文件。其中,165个为Java源文件,11个为XML配置文件,4个为YAML配置文件,2个为Git忽略文件,1个为Dockerfile,1个为LICENSE文件,1个为Markdown文件,1个为JSON文件,1个为Maven命令行脚本,以及1个为Windows命令文件。该系统旨在提供全面的学生信息管理功能。
该源码为基于Vue2、swiper和elementUI构建的电商购物网站前台设计,包含223个文件,其中包括121个PNG图片、28个JPG图片、28个Vue组件文件、22个JavaScript文件、8个JSON文件、6个CSS文件、4个JPEG图片、2个HTML文件、1个gitignore文件和1个Markdown文件。项目适用于搭建功能完善的电商购物网站前台界面。
WPF主题和语言切换功能示例
钳口校准器_三维3D设计图纸.zip
lstm时间序列预测 基于pytorch搭建多特征CNN-LSTM时间序列预测
技术资料分享技术资料笔记本大拆解图重要技术.zip
耐热链轮输送线_三维3D设计图纸.zip
本项目为基于Java和Kotlin开发的Android经典蓝牙框架设计源码,共计66个文件,涵盖17个Java源文件、16个XML布局文件、10个PNG资源文件、4个Gradle构建文件,同时包含必要的Git忽略文件、属性文件和项目规范文件。该框架支持Android传统蓝牙通信,适用于蓝牙应用开发需求。
该项目为华夏南山松养老保险系统设计源码,采用多语言开发,包含157个文件,涵盖38个SCSS样式文件、29个JavaScript脚本文件、20个Markdown文档、15个HTML页面、11个XML配置文件、9个JSON数据文件、6个C/C++头文件、4个MATLAB脚本文件、3个CSS样式文件以及3个PNG图片文件。该系统以JavaScript为主要开发语言,并整合了C、MATLAB、CSS、C++、C#、Java等多种编程语言,旨在提供全面的养老保险管理解决方案。
yuv播放器,用于多媒体开发,查看yuv格式的文件
一款纯VF控制的变频器方案方案说明:可做0.2KW7.5KW 220V,0.2KW75KW 380V,富士通MB90F462A LQFP64单片机控制,可提供源码及电路原理图,PCB图。
本项目是一款基于JetBrains平台的微信小程序插件设计源码,涉及Kotlin、TypeScript、HTML、Java等多语言开发。源码文件共计248个,其中Kotlin文件145个,XML文件19个,TypeScript文件18个,SVG文件13个,模板文件10个,HTML文件9个,Java文件8个,属性文件7个,FT文件6个,JSON文件3个。该插件致力于提升微信小程序的开发效率与用户体验。
【Python游戏开发】扫雷游戏demo图片资源素材
转子自动化焊接检测工作台_三维3D设计图纸.zip
本项目是一款基于Vue框架开发的收费系统源码,包含1133个文件,涵盖487个Vue组件、237个JavaScript脚本、195个SVG图形、142个PNG图片、19个JPG图片、11个SCSS样式表、9个CSS样式表、8个JSON数据文件、3个批处理文件和2个命令行文件。该系统以Vue、JavaScript、CSS和HTML为主要开发语言,适用于各类收费场景的设计与实现。