书签 分享 收藏 举报 版权申诉 / 26

类型表单数据关联Struts.docx

  • 文档编号:4240597
  • 上传时间:2022-11-28
  • 格式:DOCX
  • 页数:26
  • 大小:430.06KB

radioproperty="select"onblur="displayList('pubs')"value="pubs"/>

根据出版社

SelectTitle:


submitproperty="order"value="Order"/>

  

resetproperty="cancel"value="Cancel"/>

form>

html>

3、由于在前面的order.jsp中使用了一个外部order.js

(1)右击站点的根目录

输入文件名称为order.js

(2)修改该文件在保存时的编码方式

由于Eclipse在,默认时是以UTF-8的编码方式保存*.js文件,因此在其中的中文将会被改变为乱码。

应该改变为gb2312编码方式。

改变为gb2312

(3)编程该order.js文件

varhttpRequest;

varurl;

functionstartup()

{

document.forms[0].subscriptionID.focus=true;

}

functiongetHTTPRequestObject()//该函数为通用的

{

varhttpRequestObject;

if(window.XMLHttpRequest)

{//Mozilla,Safari,...

httpRequestObject=newXMLHttpRequest();

}

elseif(window.ActiveXObject)

{//IE

try

{

httpRequestObject=newActiveXObject("Microsoft.XMLHTTP");

}

catch(e)

{

try

{

httpRequestObject=newActiveXObject("Msxml2.XMLHTTP");

}

catch(e2)

{

alert("您的浏览器有问题!

");

}

}

}

returnhttpRequestObject;

}

functioninit()

{

httpRequest=getHTTPRequestObject();

varurl="/StrutsAJAXWebApp/processorder.do";

httpRequest.open("POST",url,true);

httpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

}

functionvalidate(formObj)

{

init();

httpRequest.onreadystatechange=processHttpResponseSubscriptionValidator;

httpRequest.send("subscriptionID="+formObj.subscriptionID.value);

}

functiondisplayList(field)

{

init();

titles.innerHTML="";

httpRequest.onreadystatechange=processHttpResponseListHandler;

httpRequest.send("select="+escape(field));

}

functiondisplayTitles(formObj)

{

init();

varindex=formObj.list.selectedIndex;

varval=formObj.list.options[index].value;

httpRequest.onreadystatechange=processHttpResponseTitlesHandler;

httpRequest.send("list="+val);

}

functionprocessHttpResponseSubscriptionValidator()//该函数实现对用户的ID进行实时识别的

{

if(httpRequest.readystate==4)

{

if(httpRequest.status==200)

{

varmessageObj=httpRequest.responseXML.getElementsByTagName("message")[0];

varmessage=messageObj.childNodes[0].nodeValue;

if(message=="true")

{

document.getElementById("showErrorText").innerHTML="您输入的SubscriptionID是有效的!

";

document.LibraryForm.order.disabled=false;

}

else

{

document.getElementById("showErrorText").innerHTML="您输入的SubscriptionID是无效的!

";

document.LibraryForm.order.disabled=true;

}

}

elseif(httpRequest.status==404)

{

alert("没有找到与所请求的文件相匹配的资源!

");

}

else

{

alert("你所请求的页面发生异常,错误代码为:

"+httpRequest.status);

}

}

else

{

document.getElementById("showErrorText").innerHTML="检测中,请稍等...";

}

}

 

functionprocessHttpResponseTitlesHandler()

{

if(httpRequest.readystate==4)

{

if(httpRequest.status==200)

{

document.getElementById("showErrorText").innerHTML="";//除掉状态提示文字

vartitles=document.getElementById("titles");

varindexObj=httpRequest.responseXML.getElementsByTagName("index")[0];

varindex=indexObj.childNodes[0].nodeValue;

vartemp="";

for(vari=0;i

varlistObj=httpRequest.responseXML.getElementsByTagName("list")[i];

temp=temp+""+listObj.childNodes[0].nodeValue+"";

}

temp=temp+"";

titles.innerHTML=temp;

}

elseif(httpRequest.status==404)

{

alert("没有找到与所请求的文件相匹配的资源!

");

}

else

{

alert("你所请求的页面发生异常,错误代码为:

"+httpRequest.status);

}

}

else

{

document.getElementById("showErrorText").innerHTML="检测中,请稍等...";

}

}

functionprocessHttpResponseListHandler()

{

varprefix;

if(httpRequest.readystate==4)

{

if(httpRequest.status==200)

{

document.getElementById("showErrorText").innerHTML="";//除掉状态提示文字

varlist=document.getElementById("list");

varauthorOption=document.getElementById("select")

if(authorOption.checked){

prefix="A";

}else{

prefix="P";

}

varlist=document.getElementById("selectionList");

varindexObj=httpRequest.responseXML.getElementsByTagName("index")[0];

varindex=indexObj.childNodes[0].nodeValue;

vartemp="";

for(vari=0;i

varlistObj=httpRequest.responseXML.getElementsByTagName("list")[i];

temp=temp+""+listObj.childNodes[0].nodeValue+"";

}

temp=temp+"";

list.innerHTML=temp;

}

elseif(httpRequest.status==404)

{

alert("没有找到与所请求的文件相匹配的资源!

");

}

else

{

alert("你所请求的页面发生异常,错误代码为:

"+httpRequest.status);

}

}

else

{

document.getElementById("showErrorText").innerHTML="检测中,请稍等...";

}

}

4、添加ActionForm

设置该ActionForm的名称为orderActionForm,类名称为com.px1987.webajax.actionform.OrderActionForm

并且添加各个相关的属性(包括所有的属性-----静态和动态)

5、添加Action类

设置该Action类的特征参数/processorder,com.px1987.webajax.action.OrderAction

(1)将产生出下面的

(2)编程该Action

packagecom.px1987.webajax.action;

importjavax.servlet.http.HttpServletRequest;

importjavax.servlet.http.HttpServletResponse;

importorg.apache.struts.action.Action;

importorg.apache.struts.action.ActionForm;

importorg.apache.struts.action.ActionForward;

importorg.apache.struts.action.ActionMapping;

importcom.px1987.webajax.actionform.OrderActionForm;

importjava.util.*;

importjava.io.*;

publicclassOrderActionextendsAction

{

privateHashtabletitles;

finalprivateStringvalidID="yang";//实际改变为对数据库表访问

publicActionForwardexecute(ActionMappingmapping,ActionFormform,

HttpServletRequestrequest,HttpServletResponseresponse)

{

OrderActionFormorderActionForm=(OrderActionForm)form;//TODOAuto-generatedmethodstub

this.populateTitles();

Stringoption=null;

Stringkey=null;

String[]list=null;

StringxmlString=null;

StringsubscriptionID=null;

//下面的代码是实现实时校验

subscriptionID=request.getParameter("subscriptionID");

if(subscriptionID!

=null)

{

Stringstatus=""+this.checkValidID(subscriptionID)+"";

this.writeResponse(response,status);

}

//下面的代码是实现根据用户对“作者”或者“出版社”的类型选择来动态地获得对应的信息以放到第一下拉列表框中

option=request.getParameter("select");

key=request.getParameter("list");

if(option!

=null)

{

if(option.equals("author"))

{

list=this.populateAuthors();

xmlString=this.getXMLData(list);

this.writeResponse(response,xmlString);

}

elseif(option.equals("pubs"))

{

list=this.populatePubs();

xmlString=this.getXMLData(list);

this.writeResponse(response,xmlString);

}

}

//下面的代码是实现根据用户对第一下拉列表框中的选择的项目,对应地获得相应的信息并在第二个下拉列表框中显示输出

if(key!

=null)

{

list=this.getTitle(key);

xmlString=this.getXMLData(list);

this.writeResponse(response,xmlString);

}

returnnull;

}

publicvoidwriteResponse(HttpServletResponseresp,Stringoutput)

{

resp.setContentType("text/xml;charset=GBK");

resp.setHeader("Cache-Control","no-cache");

try

{

resp.getWriter().write(output);

}

catch(IOExceptione)

{

System.out.println(e.getMessage());

}

}

publicString[]getTitle(Stringkey)

{

return(String[])titles.get(key);

}

privateString[]populateAuthors()

{//在实际应用中,该数据可以来源于某个数据库表的某列

举报
举报
版权申诉
版权申诉
word格式文档无特别注明外均可编辑修改;预览文档经过压缩,下载后原文更清晰! 立即下载
配套讲稿:

如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

特殊限制:

部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

关 键  词:
表单 数据 关联 Struts
提示  冰豆网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:表单数据关联Struts.docx
链接地址:https://www.bdocx.com/doc/4240597.html
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2008-2022 冰点文档网站版权所有

经营许可证编号:鄂ICP备2022015515号-1

收起
展开