跟我学AJAX技术——实现表单数据实时关联的Web订单的应用示例(第二部分)_第1页
跟我学AJAX技术——实现表单数据实时关联的Web订单的应用示例(第二部分)_第2页
跟我学AJAX技术——实现表单数据实时关联的Web订单的应用示例(第二部分)_第3页
跟我学AJAX技术——实现表单数据实时关联的Web订单的应用示例(第二部分)_第4页
跟我学AJAX技术——实现表单数据实时关联的Web订单的应用示例(第二部分)_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料1.1 跟我学ajax技术实现表单数据实时关联的web订单的应用示例(第二部分)1.1.1 相关后台相关的java程序1、为该order.jsp提供一个servlet程序(1)类名称为processorder,包名称为com.px1987.webajax.servlet(2)url-pattern为:/processorder(3)将产生出下面的servlet(4)编程该servlet程序代码package com.px1987.webajax.servlet;import javax.servlet.*;import javax.ser

2、vlet.http.*;import java.io.*;import java.util.*;public class processorder extends httpservlet private hashtable titles; final private string validid = yang; /实际改变为对数据库表访问 public void init() this.populatetitles(); public void doget(httpservletrequest req, httpservletresponse resp) throws servletexcep

3、tion, ioexception this.dopost(req, resp); public void dopost(httpservletrequest req, httpservletresponse resp) throws servletexception, ioexception string option = null; string key = null; string list = null; string xmlstring = null; string subscriptionid = null;/下面的代码是实现实时校验 subscriptionid = req.ge

4、tparameter(subscriptionid); if (subscriptionid != null) string status = + this.checkvalidid(subscriptionid) + ; this.writeresponse(resp, status);/*下面的代码是实现根据用户对“作者”或者“出版社”的类型选择来动态地获得对应的信息以放到第一下拉列表框中*/option = req.getparameter(select); key = req.getparameter(list); if (option != null) if (option.equa

5、ls(author) list = this.populateauthors(); xmlstring = this.getxmldata(list); this.writeresponse(resp, xmlstring); else if (option.equals(pubs) list = this.populatepubs(); xmlstring = this.getxmldata(list); this.writeresponse(resp, xmlstring); /*下面的代码是实现根据用户对第一下拉列表框中的选择的项目,对应地获得相应的信息并在第二个下拉列表框中显示输出*/

6、 if (key != null) list = this.gettitle(key); xmlstring = this.getxmldata(list); this.writeresponse(resp, xmlstring); public void writeresponse(httpservletresponse resp, string output) throws ioexception resp.setcontenttype(text/xml;charset=gbk); resp.setheader(cache-control, no-cache); resp.getwrite

7、r().write(output); public string gettitle(string key) return (string) titles.get(key); private string populateauthors() /在实际应用中,该数据可以来源于某个数据库表的某列 string authors = new string7; authors0 = -; authors1 = 张三; authors2 = 李四; authors3 = 王五; authors4 = 张四; authors5 = 李五; authors6 = 王六; return authors; priv

8、ate string getxmldata(string data) string xmlstring = ; xmlstring = xmlstring + ; xmlstring = xmlstring + + data.length + ; for (int i = 0; i data.length; i+) xmlstring = xmlstring + + datai + ; xmlstring = xmlstring + ; return xmlstring; private string populatepubs() /在实际应用中,该数据可以来源于某个数据库表的某列 strin

9、g pubs = new string5; pubs0 = -; pubs1 = 出版社1; pubs2 = 出版社2; pubs3 = 出版社3; pubs4 = 出版社4; return pubs; private void populatetitles() titles = new hashtable(); titles.put(a0, new string *空白*); titles.put(a1, new string 书名称1); titles.put(a2, new string 书名称2); titles.put(a3, new string 书名称3); titles.put

10、(a4, new string 书名称4); titles.put(a5, new string 书名称5); titles.put(a6, new string 书名称6); titles.put(p0, new string  ); titles.put(p1, new string 书名称7, 书名称8, 书名称9); titles.put(p2, new string 书名称10); titles.put(p3, new string 书名称11); titles.put(p4, new string 书名称12,书名称13, 书名称14,书名称15, 书名称16); private boolean checkvalidid(string userinputsubscriptionid) boolean okornot=false;/实际应该通过访问数据库表中的数据来识别 if (this.validid.equals(userinputsubscriptionid) okornot=true; else okornot=false; return okornot; 2、执行该页面(1)启动服务器(2)输入http:/localhost:8080/ajaxweba

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论