大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> JSP专区 -> 使用JSP + JAVABEAN + XML 开发的一个例子

使用JSP + JAVABEAN + XML 开发的一个例子

时间: 2021-07-31 作者:daque

本例子是参考了少许网站上相关jsp 对 xml 的操纵的关系文书档案,又贯串了少许部分的领会。例子波及的实质是,开拓的一个企业里面定餐体例后盾处置端的局部代码,功效重要会合在对于餐馆基础消息的处置。该例子自己开拓的来由是我在原公司和共事们一个打趣的一局部。特此也表白对那些一道同事的伙伴们的担心。例子自己是在tomcat4.01 平台下运转的b/s构造的程式。相关tomcat 的摆设,这边不做证明。只解说一下关系文献及文献夹的目次构造。目次构造证明:/tomcat/webapps/canyin/                    -----主目次/tomcat/webapps/canyin/jsp/               -----jsp 文献目次/tomcat/webapps/canyin/jsp/admin/       -----实行后盾处置的jsp 文献的寄存目次/tomcat/webapps/canyin/web-inf/classes/canyin/               ------javabean 文献的寄存目次/tomcat/webapps/canyin/data/   -----xml 文献寄存目次/tomcat/webapps/root/           -----tomcat 启用文献寄存文献夹,只寄存了index.html 文献文献大略证明:/tomcat/webapps/canyin/data/users.xml    -----记委派户消息/tomcat/webapps/canyin/data/restaurants.xml  -----记载餐馆的普通消息/tomcat/webapps/root/index.html       -----首页,页面展示输出框,诉求用户输出用户名,暗号/tomcat/webapps/canyin/jsp/loginjudge.jsp       -----用户身份确定页面,按照用户称呼和暗号确定页面是转入后盾处置端,仍旧前台存户端。本例子中,用户身份一旦确觉得有处置权力,不妨加入后盾处置端,就径直跳到餐馆基础消息处置页面,简化证明的过程。/tomcat/webapps/canyin/jsp/admin/admin_rest.jsp    -----餐馆基础消息处置页面,处置餐馆的称呼,电话,地方等消息/tomcat/webapps/canyin/web-inf/classes/canyin/checksessionbean.class  ----- 后盾处置端检验和测定标记用户身份的session 的值,即使不是处置员的话,跳回登岸页面。              /tomcat/webapps/canyin/web-inf/classes/canyin/connxmlbean.class  -----贯穿xml 文献/tomcat/webapps/canyin/web-inf/classes/canyin/writexmlbean.class  -----写入xml文献文献精细引见及附带代码证明。/tomcat/webapps/canyin/data/users.xml    代码:  <?xml version="1.0" encoding="utf-8" ?> - <users>  <user name="joard" password="joard" roles="admin" />   <user name="joard01" password="joard01" roles="user" />   <user name="joard02" password="joard02" roles="user" />   </users> 证明:字段含意是用户名,暗号以及用户的身份 /tomcat/webapps/canyin/data/restaurants.xml  代码:  <?xml version="1.0" encoding="utf-8" ?> - <restaurants num="10">- <restaurant id="1">  <name>上海亭快餐店</name>   <phone>021-76546726</phone>   <address>百老汇广场b座</address>   </restaurant>- <restaurant id="8">  <name>香格里拉大饭馆</name>   <phone>021-2312134</phone>   <address>南京路1023号</address>   </restaurant>  </restaurants>证明:<num>属性是记载在restaurants.xml 文献中所有有过几何条记载,每新增一条,不管此后简略能否,该值城市减少1,就好象数据库中风气运用的机动减少1的id 项。用来给新增的 <restaurant>的属性<id>赋一个独一的值。其它的字段道理比拟鲜明。/tomcat/webapps/root/index.html       (简单的html代码)代码:<html><head><title>oddworld 餐饮体例</title><meta http-equiv="content-type" content="text/html; charset=utf8"></head><body onload="javascript:dataform.username.focus()"><div align="center">  <table width="100%" border="0" cellspacing="0" cellpadding="0" height="22">    <tr>       <td width="1"><img src="images/top_r1.gif" width="62" height="22"></td>      <td width=150 align="center"> 餐饮体例登录 </td>      <td><img src="images/top_r2.gif" width="294" height="22"></td>    </tr>  </table>  <br>  <br>  <table width="300" border="0" cellspacing="1" cellpadding="0" >    <tr>     <td height="200" valign="top" align="center">       <p align="center">        <table width="100%" border="0" cellspacing="1" cellpadding="5" bgcolor=#999999 class=a9px>          <tr>             <td bgcolor="#efefef">餐饮体例登录</td>        </tr>        <tr>             <td bgcolor="#ffffff" valign="top" align="center">               <table width="100%" border="0" cellspacing="0" cellpadding="0">                <form name=dataform method=post action=''canyin/jsp/loginjudge.jsp''>                  <tr>                     <td width="100"><b>登录名:</b></td>                    <td>                       <input maxlength=16               name="username" class=stedit value="joard">                    </td>                  </tr>                  <tr>                    <td width="100"><b>暗号:</b></td>                    <td>                      <input  class=stedit  maxlength=16                   name="userpass" type=password value="oddworld">                    </td>                  </tr>                </form>              </table>            <br>              <table border=0 cellpadding=0 cellspacing=0>                <tbody>                 <tr>                   <td>                     <input  class=stbtm  name=update onclick="javascript:if (checkform()==false);" type=button value="登    录">                  </td>                  <td> </td>                  <td>                     <input class=stbtm name=submit onclick="javascript:window.location.href=''index.asp?myjoke=1'';" type=button value="窜改暗号">                  </td>                  <td> </td>                </tr>                </tbody>               </table>              <br>            </td>        </tr>      </table>    </td>  </tr></table></div></body></html>     <script language=javascript><!--function checkform(){  var checkblank = /^(\s*|(\ )|(\.))*$/; if (checkblank.test(dataform.username.value))    {          alert("登录名不许为空!");   return false;          }                   if (checkblank.test(dataform.userpass.value))    {          alert("暗号不许为空!");   return false;          }       window.dataform.submit();   }--></script>证明:把用户称呼和用户暗号提交到/tomcat/webapps/canyin/jsp/loginjudge.jsp       /tomcat/webapps/canyin/web-inf/classes/canyin/checksessionbean.class  (代码是相映的java 文献)package canyin;import javax.servlet.http.httpsession;import javax.servlet.http.httpservletrequest;public class checksessionbean {  private boolean bolcheckpass=false; private httpservletrequest request = null;  public boolean checksessionbean(httpservletrequest request,string strsessionname,string strcheckvalue){   public boolean checksessionbean(httpservletrequest request){  httpsession session = request.getsession(false);  return(bolcheckpass);    if (strsessionname==null || strcheckvalue==null){   return(bolcheckpass);  }else{   if (session!=null && session.getvalue(strsessionname)!=null){    bolcheckpass=session.getvalue(strsessionname).equals(strcheckvalue);   }        return(bolcheckpass);  } }}证明:检查参数字传送入的session 称呼的数值和参数字传送入的字段的数值能否十分。/tomcat/webapps/canyin/web-inf/classes/canyin/connxmlbean.class  代码:package canyin;import javax.xml.parsers.*;import javax.xml.transform.*;import javax.xml.transform.dom.domsource;import javax.xml.transform.stream.streamresult;import org.w3c.dom.*;public class connxmlbean {  private documentbuilderfactory factory=null; private documentbuilder builder=null; private document doc=null;  public connxmlbean(){}   public string connxml(string xmlfilename){    string strexc="";    try{   factory = documentbuilderfactory.newinstance();       builder=factory.newdocumentbuilder();       doc=builder.parse(xmlfilename);       doc.normalize();       }catch(exception e){       strexc=e.tostring();    }        return(strexc); }  public document getxmldoc(){    return(doc); }}证明:翻开一个指定xml 文献/tomcat/webapps/canyin/web-inf/classes/canyin/writexmlbean.class  代码:package canyin;import javax.xml.parsers.*;import javax.xml.transform.*;import javax.xml.transform.dom.domsource;import javax.xml.transform.stream.streamresult;import java.io.file;import org.w3c.dom.*;public class writexmlbean {  public writexmlbean(){}   public string writexml(document doc,string xmlfilename){    string strexc="";    try{   transformerfactory tfactory = transformerfactory.newinstance();    transformer transformer = tfactory.newtransformer();    domsource source = new domsource(doc);    streamresult result = new streamresult(new file(xmlfilename));    transformer.transform(source,result);        }catch(exception e){       strexc=e.tostring();    }        return(strexc); } }证明:写入dom 的实质到一个指定的xml 文献。/tomcat/webapps/canyin/jsp/loginjudge.jsp       代码:<%--  oddworld 餐饮处置体例(简体华文版) 2002年12月1日 copy right by joard ast    loginjudge.jsp 功效:用户身份校验,按照 /data/user.xml 文献内标示的用户各别的身份 确定转入后盾处置页面,仍旧存户订餐页面。 --%><%@ page contenttype="text/html;charset=utf8" %><%@ page language="java" import="javax.xml.parsers.*" %><%@ page import="org.w3c.dom.*" %><%@ page import="canyin.*" %> <jsp:usebean id="xmlbean" class="canyin.connxmlbean" scope="page" /><%session.setmaxinactiveinterval(1800);document doc;nodelist users;string strexc="";string strusername,strpassword;strusername=(string)request.getparameter("username");strpassword=(string)request.getparameter("userpass");//校验数据能否为空if (strusername=="" || strpassword=="" ){ out.println("<script language=''javascript''>"); out.println("alert(''用户名或暗号有空值!'');"); out.println("window.location.href=''/index.html'';"); out.println("</script>"); return;}xmlbean.connxml("webapps/canyin/data/users.xml");doc=xmlbean.getxmldoc();try{ users =doc.getelementsbytagname("user");            for (int i=0;i<users.getlength();i++){        element user=(element) users.item(i);           string stratrnamevalue=user.getattributenode("name").getnodevalue();        string stratrpasswordvalue=user.getattributenode("password").getnodevalue();        string stratrrolevalue=user.getattributenode("roles").getnodevalue();                                 if (stratrnamevalue.equals(strusername) && stratrpasswordvalue.equals(strpassword)){                  if (stratrrolevalue.equals("admin")){          out.println("<script language=''javascript''>");    out.println("alert(''欢送处置员登岸体例!'');");    out.println("</script>");        //树立标示用户身份的 session(sesuserrole) ,处置员身份为 admin    session.setattribute("sesuserrole","admin");        //跳转到处置页面    response.sendredirect("admin/admin_rest.jsp");    return;             }else{          //树立标示用户身份的 session(sesuserrole) ,处置员身份为 user          session.setattribute("sesuserrole","user");                    //跳转到普遍用户页面          response.sendredirect("index.jsp");                 return;         }        }else{         out.println("<script language=''javascript''>");   out.println("alert(''用户名或暗号缺点!'');");   out.println("history.go(-1);");   out.println("</script>");   return;        } }}catch(exception e){     strexc=e.tostring();}%>证明:......./tomcat/webapps/canyin/jsp/admin/admin_rest.jsp    代码:<%--  oddworld 餐饮处置体例(简体华文版) 2002年12月1日 copy right by joard ast    admin_rest.jsp 功效:后盾处置页面,餐馆处置页面。 --%><%@ page contenttype="text/html;charset=utf8" %><%@ page language="java" import="javax.xml.parsers.*" %><%@ page import="javax.xml.transform.*" %><%@ page import="org.w3c.dom.*" %><%@ page import="canyin.*" %> <%@ include file="../../include/sys_dialog.jsp" %><jsp:usebean id="checksessionbean" class="canyin.checksessionbean" scope="page" /><jsp:usebean id="xmlbean" class="canyin.connxmlbean" scope="page" /><jsp:usebean id="writexmlbean" class="canyin.writexmlbean" scope="page" /><%//校验可户身份,确定是否处置员if(!checksessionbean.checksessionbean(request,"sesuserrole","admin")){ out.print(showdialog("您没有处置的权力!","/index.html")); return;}//从餐馆材料文献 rest.xml 中获得关系数据document doc;nodelist restaurants;string stract;int intid=0;string stroperation="show";//接收外部传入的参数stract=(string)request.getparameter("act");xmlbean.connxml("webapps/canyin/data/restaurants.xml");doc=xmlbean.getxmldoc();restaurants =doc.getelementsbytagname("restaurant");//按照外部传入的参数来确定对 restaurant.xml 文献的操纵if (stract!=null){ if(stract.equals("addnewdo")){    string strname;  string strphone;  string straddress;  text textseg;    strname=(string)request.getparameter("name").trim();  strphone=(string)request.getparameter("phone").trim();  straddress=(string)request.getparameter("address").trim();    //数据校验  if(strname==null){   out.print(showdialog("餐馆称呼不许为空!"));   return;  }  if(strphone==null){   out.print(showdialog("餐馆电话不许为空!"));   return;  }  /*if(straddress==null){   out.print(showdialog("餐馆地方不许为空!"));   return;  }*/    //校验数据的独一性  for(int i=0;i<restaurants.getlength();i++){   element restaurant=(element) restaurants.item(i);   if(((string)restaurant.getelementsbytagname("name").item(0).getfirstchild().getnodevalue()).equals(strname)){    out.print(showdialog("餐馆称呼反复!"));    return;    }else{    if(((string)restaurant.getelementsbytagname("name").item(0).getfirstchild().getnodevalue()).equals(strphone)){     out.print(showdialog("餐馆电话反复!"));     return;    }   }     }          //获得已有的记载数,给新增的餐馆记载设定独一的递加的id 属性  int intnum=0;  element restnum=(element)doc.getelementsbytagname("restaurants").item(0);  intnum=integer.parseint(restnum.getattributenode("num").getnodevalue());   intnum+=1;    //为restaurants的属性num 的数值加1  restnum.getattributenode("num").setnodevalue(string.valueof(intnum));  //新增节点      element newrestaurant=doc.createelement("restaurant");    attr newarrid=doc.createattribute("id");  //attribute newarrid = new attribute("id",string.valueof(intnum));    textseg=doc.createtextnode(string.valueof(intnum));  newarrid.setvalue(string.valueof(intnum));  newrestaurant.setattributenode(newarrid);    element newname=doc.createelement("name");  textseg=doc.createtextnode(strname);  newname.appendchild(textseg);  newrestaurant.appendchild(newname);    element newphone=doc.createelement("phone");  textseg=doc.createtextnode(strphone);  newphone.appendchild(textseg);  newrestaurant.appendchild(newphone);    element newaddress=doc.createelement("address");  textseg=doc.createtextnode(straddress);  newaddress.appendchild(textseg);  newrestaurant.appendchild(newaddress);    doc.getdocumentelement().appendchild(newrestaurant);  //挪用bean 写入相映的xml文献  writexmlbean.writexml(doc,"webapps/canyin/data/restaurants.xml");  response.sendredirect(request.getrequesturi());    return; } if(stract.equals("modido")){  string strname;  string strphone;  string straddress;  text textseg;  int modiid;  //记载要窜改的记载是item(i)的哪一项  int inti=0;    strname=(string)request.getparameter("name").trim();  strphone=(string)request.getparameter("phone").trim();  straddress=(string)request.getparameter("address").trim();  modiid=integer.parseint(request.getparameter("recordid").trim());    //数据校验  if(strname==null){   out.print(showdialog("餐馆称呼不许为空!"));   return;  }  if(strphone==null){   out.print(showdialog("餐馆电话不许为空!"));   return;  }  if(modiid==0){   out.print(showdialog("你要窜改餐馆的记载不生存!"));   return;  }  /*if(straddress==null){   out.print(showdialog("餐馆地方不许为空!"));   return;  }*/    //标记表露记载生存  boolean recordexist=false;    //校验数据的独一性  for(int i=0;i<restaurants.getlength();i++){   element restaurant=(element) restaurants.item(i);      if(integer.parseint(restaurant.getattributenode("id").getnodevalue())==modiid){    recordexist=true;    inti=i;   }      if(((string)restaurant.getelementsbytagname("name").item(0).getfirstchild().getnodevalue()).equals(strname) && integer.parseint(restaurant.getattributenode("id").getnodevalue())!=modiid ){    out.print(showdialog("餐馆称呼反复!"));    return;    }else{    if(((string)restaurant.getelementsbytagname("name").item(0).getfirstchild().getnodevalue()).equals(strphone) && integer.parseint(restaurant.getattributenode("id").getnodevalue())!=modiid ){     out.print(showdialog("餐馆电话反复!"));     return;    }   }     }      if(!recordexist){   out.print(showdialog("你要窜改餐馆的记载不生存!"));   return;  }else{   //举行记载变动的操纵   try{    element modirestaurant=(element) restaurants.item(inti);    modirestaurant.getelementsbytagname("name").item(0).getfirstchild().setnodevalue(strname);    modirestaurant.getelementsbytagname("phone").item(0).getfirstchild().setnodevalue(strphone);    modirestaurant.getelementsbytagname("address").item(0).getfirstchild().setnodevalue(straddress);        //挪用bean 写入相映的xml文献    writexmlbean.writexml(doc,"webapps/canyin/data/restaurants.xml");      response.sendredirect(request.getrequesturi());      return;        }catch(exception e){}  } } //举行简略操纵 if(stract.equals("del")){  int delid;  //记载要窜改的记载是item(i)的哪一项  int inti=0;  delid=integer.parseint(request.getparameter("recordid").trim());  if(delid==0){   out.print(showdialog("你要窜改餐馆的记载不生存!"));   return;  }    file://标记表露记载生存  boolean recordexist=false;  //校验数据的独一性  for(int i=0;i<restaurants.getlength();i++){   element restaurant=(element) restaurants.item(i);      if(integer.parseint(restaurant.getattributenode("id").getnodevalue())==delid){    recordexist=true;    inti=i;   }  }    if(!recordexist){   out.print(showdialog("你要简略餐馆的记载不生存!"));   return;  }else{   //举行记载简略的操纵   try{    node delnode=(node)restaurants.item(inti);        doc.getelementsbytagname("restaurants").item(0).removechild(delnode);    //挪用bean 写入相映的xml文献    writexmlbean.writexml(doc,"webapps/canyin/data/restaurants.xml");    response.sendredirect(request.getrequesturi());      return;        }catch(exception e){}  } }}//由外部传入参数确定页面相映的处置状况if (stract==null){ stroperation="show";}else{ if (stract.equals("modi")){  stroperation="modi";  intid=integer.parseint(request.getparameter("recordid")); }else{  if(stract.equals("addnew")){   stroperation="addnew";  }else{   stroperation="show";  } }}//即使为空记载,则变换页面状况为“新增”if (restaurants.getlength()==0){ stroperation="addnew";}%><html><head><title>oddworld 餐饮体例</title><meta http-equiv="content-type" content="text/html; charset=utf8"><meta http-equiv="expires" content="0"><link rel="stylesheet" href="../../include/itsp.css" type="text/css"></head><body ><div align="center">  <table width="100%" border="0" cellspacing="0" cellpadding="0" height="22">    <tr>       <td width="1"><img src="../../images/top_r1.gif" width="62" height="22"></td>      <td width=150 align="center"> 餐饮体例处置--餐馆处置</td>      <td><img src="../../images/top_r2.gif" width="294" height="22"></td>   <td width=100 align="center"><a href="/index.html">[ 退出体例 ]</a></td>    </tr>  </table>  <br>  <br>  <table bgcolor="#999999" align=center border=0 cellpadding=1 cellspacing=1 width="90%">    <tbody>     <tr bgcolor="#efefef" align="center" valign="middle">       <td class=tttable height=30 width="20"> </td>      <td class=tttable height=30 width="0">餐馆称呼</td>      <td class=tttable height=30 width="0">餐馆电话</td>      <td class=tttable height=30 width="0">         <div align="center">餐馆地方</div>      </td>      <td class=tttable height=30 width="30">         <div align="center">窜改</div>      </td>      <td class=tttable height=30 width="30">         <div align="center">简略</div>      </td>    </tr><% for(int i=0;i<restaurants.getlength();i++) {  element restaurant=(element) restaurants.item(i);    if (stroperation=="modi" && integer.parseint(restaurant.getattributenode("id").getnodevalue())==intid){%>    <%//表露窜改的方法%>    <tr align="center" bgcolor="#ffffff" valign="middle">       <form name=dataform action="<%=request.getrequesturi()%>?act=modido" method="post"  onsubmit=''return checkform(this);'' >        <td class=tdsmall height=25 width="20">           <input type="hidden" name="recordid" value="<%=restaurant.getattributenode("id").getnodevalue()%>">          <%=(i+1)%></td>        <td class=tdsmall height=25>           <input name="name" class=stedit                  style="height: 22px; width: 150px" value="<%if(restaurant.getelementsbytagname("name").item(0).haschildnodes()){         out.print(restaurant.getelementsbytagname("name").item(0).getfirstchild().getnodevalue());                 }%>" maxlength="40" >        </td>        <td class=tdsmall height=25>           <input name="phone" class=stedit                  style="height: 22px; width: 100px" value="<%if(restaurant.getelementsbytagname("phone").item(0).haschildnodes()){         out.print(restaurant.getelementsbytagname("phone").item(0).getfirstchild().getnodevalue());                 }%>" maxlength="20" >        </td>        <td class=tdsmall height=25>           <input name="address" class=stedit                  style="height: 22px; width: 200px" value="<%                                    if(restaurant.getelementsbytagname("address").item(0).haschildnodes()){         out.print(restaurant.getelementsbytagname("address").item(0).getfirstchild().getnodevalue());                 }%>" maxlength="100" >        </td>        <td class=tdsmall height=25 width="25"><a href="javascript:if (checkform()==false);"><img border=0       height=15 src="../../images/editok.gif" width=15></a></td>        <td class=tdsmall height=25 width="25"> </td>      </form>    </tr>    <% }else{     //表露平常的方法 %>    <tr align="center" bgcolor="#ffffff" valign="middle">       <td class=tdsmall height=25 width="20"><%=(i+1)%></td>      <td class=tdsmall height=25 width="0"><%if(restaurant.getelementsbytagname("name").item(0).haschildnodes()){         out.print(restaurant.getelementsbytagname("name").item(0).getfirstchild().getnodevalue());                 }%></td>      <td class=tdsmall height=25 width="0"><%if(restaurant.getelementsbytagname("phone").item(0).haschildnodes()){         out.print(restaurant.getelementsbytagname("phone").item(0).getfirstchild().getnodevalue());                 }%></td>      <td class=tdsmall height=25 width="0">         <%        if(restaurant.getelementsbytagname("address").item(0).haschildnodes()){        out.print(restaurant.getelementsbytagname("address").item(0).getfirstchild().getnodevalue());                 }%>      </td>      <td class=tdsmall height=25 width="30"><a href="<%=request.getrequesturi()%>?act=modi&recordid=<%=restaurant.getattributenode("id").getnodevalue()%>"><img border=0         height=15 src="../../images/edit.gif" width=15></a></td>      <td class=tdsmall height=25 width="30"><img border=0         height=15         onclick="javascript:if(confirm(''您能否决定简略本记载,简略后将导至记载没辙运用?'')){window.location.href=''<%=request.getrequesturi()%>?act=del&recordid=<%=restaurant.getattributenode("id").getnodevalue()%>'';}"         src="../../images/delete.gif" style="cursor: hand" width=15> </td>    </tr>    <% } }%>    <% if (stroperation=="addnew"){    //表露新增的方法%>    <tr align="center" bgcolor="#ffffff" valign="middle">       <form name=dataform2 action="<%=request.getrequesturi()%>?act=addnewdo" method="post"  onsubmit=''return checkform2(this);'' >        <td class=tdsmall height=25 width="20"></td>        <td class=tdsmall height=25>           <input name="name" class=stedit                  style="height: 22px; width: 150px" value="" maxlength="40" >        </td>        <td class=tdsmall height=25>           <input name="phone" class=stedit                  style="height: 22px; width: 100px" value="" maxlength="20" >        </td>        <td class=tdsmall height=25>           <input name="address" class=stedit                  style="height: 22px; width: 200px" value="" maxlength="100" >        </td>        <td class=tdsmall height=25 width="25"><a href="javascript:if (checkform2()==false);"><img border=0       height=15 src="../../images/editok.gif" width=15></a></td>        <td class=tdsmall height=25 width="25"> </td>      </form>    </tr>    <% } %>    </tbody>   </table>  <br>  <table align=center border=0 cellpadding=0 cellspacing=2 width="95%">    <tbody>     <tr valign=center>       <td align=middle> <br>        <table border=0 cellpadding=0 cellspacing=0>          <tr>            <td>               <% if (stroperation=="addnew"){              %>              <input class=stbtm name=update onclick="javascript:if (checkform2()==false);" type=button value="革新记载">              <% }else{                if(stroperation=="modi"){              %>              <input class=stbtm name=update onclick="javascript:if (checkform()==false);" type=button value="革新记载">              <%                 }else{                 %>              <input class=stbtm type="button" name="button" value="新 增" onclick="javascript:window.location.href=''<%=request.getrequesturi()%>?act=addnew'';"><%                 }                } %>               </td>            <td>              <input class=stbtm type="button" name="button" value="返 回" onclick="javascript:window.location.href=''index.jsp'';">            </td>          </tr>        </table>      </td>    </tr>  </table>  <p> </p></div></body></html><script language=javascript><!--function checkform2(){ var checkblank = /^(\s*|(\ )|(\.))*$/;    if (checkblank.test(dataform2.name.value)) {          alert("餐馆称呼不许为空!");          dataform2.name.focus();   return false;          }    if (checkblank.test(dataform2.phone.value))     {          alert("餐馆电话不许为空!");          dataform2.phone.focus();   return false;          }         window.dataform2.submit();  }    function checkform(){   var checkblank = /^(\s*|(\ )|(\.))*$/; if (checkblank.test(dataform.name.value)) {          alert("餐馆称呼不许为空!");          dataform.name.focus();   return false;          }                  if (checkblank.test(dataform.phone.value)) {          alert("餐馆电话不许为空!");          dataform.phone.focus();   return false;          }                 window.dataform.submit();  }--></script>证明:本文献的抄写有很多场合并不简单,由于在程式的开拓进程中,过度简单的步调常常会带来后期保护的艰巨。开拓心得:doc.getelementsbytagname("restaurants").item(int i)的归来值是node 型,即使不是要挪用它的属性值,没有需要强迫转型为 element型。不妨径直操纵。本体例由于开拓的参考材料的缺点,以是全都沿用了强迫转型。不妨在此后的开拓中商量运用node 径直举行操纵。trim() 和 interger.parseint() 因变量都不不妨接收null 型的数值在tomcat 下安排的文献都是目次从tomcat 算起,简直情景请拜见\webapps\canyin\jsp\userjudge.jsp 里对于xml 路途的写法。对原代码感爱好的伙伴请经过如次邮箱和我接洽,joard@163.com

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.