Using JSP + JAVABEAN + XML development as an example of _jsp programming

Source: Internet
Author: User
Tags tomcat
This example is a reference to some of the Web site on JSP on the operation of XML related documents, but also combined with some personal experience. Examples of the content is the development of an enterprise internal catering system backend management part of the code, the function is mainly focused on the restaurant basic information management.





The development of the example itself was a part of a joke I had with my colleagues in the original company. I hereby express my thoughts to the friends who have worked together.





The example itself is the program of B/s structure running under the TOMCAT4.01 platform. The configuration for Tomcat is not described here. Just explain the directory structure of the related files and folders.





Directory Structure Description:


/tomcat/webapps/canyin/-----Home Directory


/tomcat/webapps/canyin/jsp/-----JSP file directory


/tomcat/webapps/canyin/jsp/admin/-----The storage directory of the JSP file that realizes the backstage management


Directory of/tomcat/webapps/canyin/web-inf/classes/canyin/------JavaBean files


/tomcat/webapps/canyin/data/-----XML File storage directory


/tomcat/webapps/root/-----Tomcat startup Files folder, only index.html files are stored





Simple File Description:


/tomcat/webapps/canyin/data/users.xml-----Record User Information


/tomcat/webapps/canyin/data/restaurants.xml-----Record basic information about restaurants








/tomcat/webapps/root/index.html-----Homepage, the page appears the input box, asks the user to enter the user name, the password








/tomcat/webapps/canyin/jsp/loginjudge.jsp-----User Identification page, according to the user name and password to determine whether the page is transferred to the backend management, or foreground client. In this example, once the user identity as a management authority, you can go to the backend management side, you jump directly to the restaurant basic information Management page, simplifying the description of the process.


/TOMCAT/WEBAPPS/CANYIN/JSP/ADMIN/ADMIN_REST.JSP-----Restaurant basic Information Management page, management of restaurant name, telephone, address and other information





/tomcat/webapps/canyin/web-inf/classes/canyin/checksessionbean.class-----The backend admin end detects the value of the session that marks the user's identity, if not the administrator, Jump back to the landing page.


/tomcat/webapps/canyin/web-inf/classes/canyin/connxmlbean.class-----Connection XML file


/tomcat/webapps/canyin/web-inf/classes/canyin/writexmlbean.class-----Write to XML file





Detailed description of the file and accompanying code instructions.





/tomcat/webapps/canyin/data/users.xml





Code:


<?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>





Description: The field meaning is the user name, the password as well as the user's identity





/tomcat/webapps/canyin/data/restaurants.xml





Code:


<?xml version= "1.0" encoding= "UTF-8"?>


-<restaurants num= "Ten" >


-<restaurant id= "1" >


<name> Shanghai Pavilion Snack Bar </name>


<phone>021-76546726</phone>


<address> Broadway Plaza, block B </address>


</restaurant>


-<restaurant id= "8" >


<name> Shangri-La hotel </name>


<phone>021-2312134</phone>


<address> Nanjing Road No. 1023th </address>


</restaurant>


</restaurants>


Description The:<num> property is a record of the total number of records in the Restaurants.xml file, each new one, regardless of whether the deletion later, this value will increase by 1, as if the database is used to automatically increase the ID of 1. Used to assign a unique value to the new <restaurant> property <id>. Other field meanings are more obvious.


/tomcat/webapps/root/index.html (simple HTML code)





Code:


<html>


<head>


<title>oddworld Catering System </title>


<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">


</head>





<body onload= "Javascript:dataform.username.focus ()" >


<div align= "center" >


<table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" height= ">"


<tr>


<TD width= "1" ><img src= "images/top_r1. GIF "width=" height= "></td>"


<TD width=150 align= "center" > Dining System Login </td>


<td><img src= "IMAGES/TOP_R2. GIF "width=" 294 "height=" ></td>


</tr>


</table>


<br>


<br>


<table width= "border=" 0 "cellspacing=" 1 "cellpadding=" 0 ">


<tr>


<TD height= "valign=" "Top" align= "center" >


<p align= "center" >


<table width= "100%" border= "0" cellspacing= "1" cellpadding= "5" bgcolor= #999999 class=a9px>


<tr>


<TD bgcolor= "#efefef" > Dining system Login </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= ><b> sign-in name:</b></td>


<td>


<input maxlength=16


Name= "username" class=stedit value= "Joard" >


</td>


</tr>


<tr>


<TD width= ><b> Password:</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= "Login" >


</td>


<td> </td>


<td>


<input class=stbtm name=submit onclick= "javascript:window.location.href= ' index.asp?myjoke=1"; "Type=button value= "Modify Password" >


</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 ("Logon name cannot be empty!");


return false;


}





if (Checkblank.test (Dataform.userpass.value))


{


Alert ("Password cannot be empty!");


return false;


}








Window.dataform.submit ();





}


-->





</SCRIPT>





Description: Submit user name and user password to/tomcat/webapps/canyin/jsp/loginjudge.jsp





/tomcat/webapps/canyin/web-inf/classes/canyin/checksessionbean.class (Code is the appropriate Java file)





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);


}


}


}





Note: Verify that the values of the session names passed in by the parameters are equal to the values of the fields passed in.





/tomcat/webapps/canyin/web-inf/classes/canyin/connxmlbean.class





Code:


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);


}


}





Description: Opens a specified XML file





/tomcat/webapps/canyin/web-inf/classes/canyin/writexmlbean.class





Code:


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);


}





}





Description: Writes the contents of the DOM to a specified XML file.





/tomcat/webapps/canyin/jsp/loginjudge.jsp





Code:


<%--Oddworld Catering Management System (Simplified Chinese edition) December 1, 2002


Copy right by Joard AST





loginjudge.jsp function: User authentication, according to the different identities of the users in/data/user.xml file


Decide to switch to the admin page or the Customer order page.


--%>





<%@ page contenttype= "text/html;charset=gb2312"%>


<%@ 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");





Verify that the data is empty


if (strusername== "" | | | strpassword== "") {


Out.println ("<script language= ' JavaScript ' >");


Out.println ("alert (' username or password has null value! ');");


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 (' Welcome admin Login System! ');");


Out.println ("</script>");





Set the session (Sesuserrole) that identifies the user, admin as admin


Session.setattribute ("Sesuserrole", "admin");





Jump to Admin page


Response.sendredirect ("admin/admin_rest.jsp");


Return





}else{


Set the session (Sesuserrole) that identifies the user as the administrator


Session.setattribute ("Sesuserrole", "user");





Jump to normal user page


Response.sendredirect ("index.jsp");


Return


}





}else{


Out.println ("<script language= ' JavaScript ' >");


Out.println ("alert (' Username or password error! ');");


Out.println ("History.go (-1);");


Out.println ("</script>");


Return


}





}


}catch (Exception e) {


Strexc=e.tostring ();


}


%>


Description: .....





/tomcat/webapps/canyin/jsp/admin/admin_rest.jsp





Code:


<%--Oddworld Catering Management System (Simplified Chinese edition) December 1, 2002


Copy right by Joard AST





admin_rest.jsp function: admin page, Restaurant Management page.


--%>





<%@ page contenttype= "text/html;charset=gb2312"%>


<%@ 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"/>





<%//Check can be household identity, judge is not the administrator


if (!checksessionbean.checksessionbean (Request, "Sesuserrole", "admin")) {


Out.print (ShowDialog ("You do not have administrative privileges!", "/index.html"));


Return


}





Get relevant data from restaurant data file Rest.xml


Document Doc;


NodeList restaurants;





String stract;


int intid=0;


String stroperation= "Show";





Accept external incoming arguments


stract= (String) request.getparameter ("act");





Xmlbean.connxml ("Webapps/canyin/data/restaurants.xml");


Doc=xmlbean.getxmldoc ();


Restaurants =doc.getelementsbytagname ("Restaurant");





To determine the operation of the Restaurant.xml file based on external parameters passed in


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 ();





Data validation


if (strname==null) {


Out.print (ShowDialog ("Restaurant name cannot be empty!");


Return


}


if (strphone==null) {


Out.print (ShowDialog ("Restaurant phone cannot be empty!");


Return


}


/*if (straddress==null) {


Out.print (ShowDialog ("Restaurant address cannot be empty!");


Return


}*/





Verify the uniqueness of the data


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 ("Duplicate restaurant name!");


Return


}else{


if ((String) restaurant.getelementsbytagname ("name"). Item (0). Getfirstchild (). Getnodevalue ()). Equals (Strphone)) {


Out.print (ShowDialog ("Restaurant phone repeat!");


Return


}


}





}











To get the number of records available, set the unique incremental id attribute for the new restaurant record


int intnum=0;


Element restnum= (Element) Doc.getelementsbytagname ("restaurants"). Item (0);


Intnum=integer.parseint (Restnum.getattributenode ("num"). Getnodevalue ());





Intnum+=1;





Value for restaurants's attribute num plus 1.


Restnum.getattributenode ("num"). setNodeValue (String.valueof (intnum));





New node


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);





The call Bean writes to the corresponding XML file


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;


Record which record you want to modify is the 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 ());





Data validation


if (strname==null) {


Out.print (ShowDialog ("Restaurant name cannot be empty!");


Return


}


if (strphone==null) {


Out.print (ShowDialog ("Restaurant phone cannot be empty!");


Return


}


if (modiid==0) {


Out.print ("You have to modify the restaurant's record does not exist!") (ShowDialog);


Return


}


/*if (straddress==null) {


Out.print (ShowDialog ("Restaurant address cannot be empty!");


Return


}*/





Flag Display record exists


Boolean recordexist=false;





Verify the uniqueness of the data


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 ("Duplicate restaurant name!");


Return


}else{


if ((String) restaurant.getelementsbytagname ("name"). Item (0). Getfirstchild (). Getnodevalue ()). Equals (Strphone) && Integer.parseint (Restaurant.getattributenode ("id"). getnodevalue ())!=modiid) {


Out.print (ShowDialog ("Restaurant phone repeat!");


Return


}


}





}











if (!recordexist) {


Out.print ("You have to modify the restaurant's record does not exist!") (ShowDialog);


Return


}else{


Action to record changes


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);





The call Bean writes to the corresponding XML file


Writexmlbean.writexml (Doc, "Webapps/canyin/data/restaurants.xml");





Response.sendredirect (Request.getrequesturi ());


Return





}catch (Exception e) {}


}


}


Make a delete operation


if (Stract.equals ("del")) {


int delid;


Record which record you want to modify is the item (i)


int inti=0;





Delid=integer.parseint (Request.getparameter ("RecordID"). Trim ());





if (delid==0) {


Out.print ("You have to modify the restaurant's record does not exist!") (ShowDialog);


Return


}





file://Flag display record exists


Boolean recordexist=false;





Verify the uniqueness of the data


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 ("You want to delete the record of the restaurant not exist!") (ShowDialog);


Return


}else{


To record a delete operation


try{


Node delnode= (node) restaurants.item (IntI);





Doc.getelementsbytagname ("restaurants"). Item (0). removechild (Delnode);





The call Bean writes to the corresponding XML file


Writexmlbean.writexml (Doc, "Webapps/canyin/data/restaurants.xml");





Response.sendredirect (Request.getrequesturi ());


Return





}catch (Exception e) {}


}





}


}





The corresponding processing state of the page is determined by the external incoming parameter


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 the record is blank, change the page status to "new"


if (Restaurants.getlength () ==0) {


Stroperation= "AddNew";


}


%>





<html>


<head>


<title>oddworld Catering System </title>


<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">


<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= ">"


<tr>


<TD width= "1" ><img src= ". /.. /images/top_r1. GIF "width=" height= "></td>"


<TD width=150 align= "center" > Catering System Management--Restaurant management </td>


<td><img src= ". /.. /images/top_r2. GIF "width=" 294 "height=" ></td>


<TD width=100 align= "center" ><a href= "/index.html" >[exit system]</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= "> </td>


<TD class=tttable height=30 width= "0" > Restaurant name </td>


<TD class=tttable height=30 width= "0" > Restaurant Tel </td>


<TD class=tttable height=30 width= "0" >


<div align= "Center" > Restaurant Address </div>


</td>


<TD class=tttable height=30 width= ">"


<div align= "center" > Modify </div>


</td>


<TD class=tttable height=30 width= ">"


<div align= "center" > Delete </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) {


%>


<%//Display the modified format%>


<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= ">"


<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=" >


</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=" >


</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=" >


</td>


<TD class=tdsmall height=25 width= "><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= "> </td>


</form>


</tr>


<%}else{


Displays the normal format%>


<TR align= "center" bgcolor= "#ffffff" valign= "Middle" >


<TD class=tdsmall height=25 width= "><%=" 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= "><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= "><img border=0"


Height=15


Onclick= "Javascript:if (Confirm (") are you sure you want to delete this record and then remove it to the record? ") {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") {


Display the new formatting%>


<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= "></td>"


<TD Class=tdsmall height=25>


<input name= "Name" Class=stedit


Style= "HEIGHT:22PX; width:150px "value=" "maxlength=" >


</td>


<TD Class=tdsmall height=25>


<input name= "Phone" class=stedit


Style= "HEIGHT:22PX; width:100px "value=" "maxlength=" >


</td>


<TD Class=tdsmall height=25>


<input name= "Address" class=stedit


Style= "HEIGHT:22PX; width:200px "value=" "maxlength=" >


</td>


<TD class=tdsmall height=25 width= "><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= "> </td>


</form>


</tr>


<%}%>


</tbody>


</table>


<br>


<table align=center border=0 cellpadding=0 cellspacing=2 width= ">"


<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= "update Record" >


<%}else{


if (stroperation== "Modi") {


%>


<input class=stbtm name=update onclick= "Javascript:if (Checkform () ==false);" Type=button value= "update Record" >


<%


}else{


%>


<input class=stbtm type= "button" name= "button" value= "Add" onclick= "javascript:window.location.href=" <%= Request.getrequesturi ()%>?act=addnew '; ' ><%


}


}%>


</td>


<td>


<input class=stbtm type= "button" name= "button" value= "returns" 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 ("Restaurant name cannot be empty!") ");


Dataform2.name.focus ();


return false;


}





if (Checkblank.test (Dataform2.phone.value))


{


Alert ("Restaurant phone cannot be empty!") ");


Dataform2.phone.focus ();


return false;


}


Window.dataform2.submit ();


}





function Checkform ()


{


var Checkblank =/^ (\s*| ( \) | (\.)) *$/;


if (Checkblank.test (Dataform.name.value))


{


Alert ("Restaurant name cannot be empty!") ");


Dataform.name.focus ();


return false;


}





if (Checkblank.test (Dataform.phone.value))


{


Alert ("Restaurant phone cannot be empty!") ");


Dataform.phone.focus ();


return false;


}








Window.dataform.submit ();


}


-->


</SCRIPT>


Note: The writing of this document is not concise, because in the development process of the program, too concise procedures often bring later maintenance difficulties.





Development experience:





Doc.getelementsbytagname ("restaurants"). The return value of item (int i) is a node type, and it is not necessary to force a transition to an element type if it is not to invoke its property value. can be directly manipulated. This system is a mandatory transformation because of the mistakes in the development of reference materials. You can consider using node as a direct operation in future development.





Neither the trim () nor the Interger.parseint () function can accept null-type values





The files that are under Tomcat are all directories from Tomcat, see \webapps\canyin\jsp\userjudge.jsp about XML paths in the details.








Friends interested in the original code please contact me through the following mailbox, joard@163.com





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.