An example of using jsp + JavaBean + XML development

Time:2022-5-2

Some examples related to JSP operation are combined with this website. The content involved in the example is part of the code of the background management end of an enterprise internal ordering system, which mainly focuses on the management of the basic information of the restaurant.

The reason for the development of the example itself is part of a joke I made with my colleagues in the original company. I would also like to express my thoughts to those friends who work together.

The example itself is in Tomcat 4 01. Programs with B / S structure running on the platform. The configuration of Tomcat} is not described here. Just explain the directory structure of relevant files and folders.

Description of directory structure:
/Tomcat / webapps / canyin / —– home directory
/Tomcat / webapps / canyin / JSP / —– JSP file directory
/Tomcat / webapps / canyin / JSP / admin / — the storage directory of JSP files for background management
/Tomcat / webapps / canyin / WEB-INF / classes / canyin / —– the directory where JavaBean files are stored
/Tomcat / webapps / canyin / data / —– XML file storage directory
/The file “webcat / index” is stored in the folder “webcat / HTML file

Brief description of the document:
/tomcat/webapps/canyin/data/users. XML —- record user information
/tomcat/webapps/canyin/data/restaurants. XML —- records the basic information of the restaurant

/tomcat/webapps/ROOT/index. HTML —– on the home page, an input box appears on the page, requiring users to enter user name and password

/tomcat/webapps/canyin/jsp/loginjudge. JSP —- user identity judgment page, which determines whether the page is transferred to the background management end or the foreground client according to the user name and password. In this example, once the user’s identity is confirmed to have management authority, he can enter the background management end and directly jump to the basic information management page of the restaurant to simplify the description process.
/tomcat/webapps/canyin/jsp/admin/admin_ rest. JSP – Restaurant basic information management page, which manages the name, telephone, address and other information of the restaurant

/tomcat/webapps/canyin/WEB-INF/classes/canyin/checkSessionBean. Class —– the background management end detects the value of session marking the user’s identity. If it is not an administrator, jump back to the login page.               
/tomcat/webapps/canyin/WEB-INF/classes/canyin/connXmlBean. Class —– connect XML file
/tomcat/webapps/canyin/WEB-INF/classes/canyin/writeXmlBean. Class —– write XML file

Detailed description of the document and attached code description.

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

Note: the meaning of the field is user name, password and user identity

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

code:
  <?xml version=”1.0″ encoding=”UTF-8″ ?> 
– <restaurants num=”10″>
– <restaurant id=”1″>
< name > Shanghai Pavilion fast food restaurant < / name >
  <phone>021-76546726</phone> 
< address > block B, Broadway Plaza < / address >
  </restaurant>
– <restaurant id=”8″>
< name > Shangri La Hotel < / name >
  <phone>021-2312134</phone> 
< address > 1023 Nanjing Road < / address >
  </restaurant>
  </restaurants>
Note: < num > attribute is recorded in restaurants How many records are there in the XML # file? For each new record, whether it is deleted later or not, the value will increase by 1, just like the ID # item that is used to automatically increase by 1 in the database. It is used to assign a unique value to the attribute < ID > of the newly added < restaurant >. The meaning of other fields is obvious.
/tomcat/webapps/ROOT/index. HTML (simple HTML code)

code:
<html>
<head>
< D title > catering system
<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=”22″>
    <tr> 
      <td width=”1″><img src=”images/top_r1.GIF” width=”62″ height=”22″></td>
< TD # width = 150 # align = “center” > login to the catering system</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 = “#efef” > login to the catering system</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 > login name:</b></td>
                    <td> 
                      <input maxlength=16 
              name=”username” class=stedit value=”joard”>
                    </td>
                  </tr>
                  <tr>
< TD # width = “100” > < 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 = “change 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 (“login name cannot be empty!”);
   return false; 
         } 

         if (Checkblank.test(dataform.userpass.value))    
{
Alert (“password cannot be empty!”);
   return false; 
         } 

      window.dataform.submit();

   }
–>

</SCRIPT>

Note: submit the user name and password to / Tomcat / webapps / canyin / JSP / loginjuge jsp       

/tomcat/webapps/canyin/WEB-INF/classes/canyin/checkSessionBean. Class (the code is the corresponding 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: check whether the value of the session {name passed in by the parameter is equal to the value of the field passed in by the parameter.

/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: open 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: write the contents of DOM to a specified XML file.

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

code:
<% — Oddworld catering management system (Simplified Chinese version) December 1, 2002
 copy right by joard ast  

 loginjudge. JSP # function: user identity verification according to / data / user Different identities of users marked in XML} file
Decide whether to go to the background management 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”);

//Check whether the data is empty
if (strUsername==”” || strPassword==”” ){
 out.println(“<script language=”javascript”>”);
 out. Println (“alert (‘user name or password has empty 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 administrator to login system! ‘);
    out.println(“</script>”);

/ / set the session (sesuserrole) that identifies the user’s identity. The administrator identity is admin
    session.setAttribute(“sesUserRole”,”admin”);

/ / jump to the management page
    response.sendRedirect(“admin/admin_rest.jsp”);
    return;

         }else{
/ / set the session (sesuserrole) that identifies the user’s identity, and the administrator identity is user
          session.setAttribute(“sesUserRole”,”user”);

/ / jump to the normal user page
          response.sendRedirect(“index.jsp”);       
          return;
         }

        }else{
         out.println(“<script language=”javascript”>”);
   out. Println (“alert (‘wrong username or password! ‘);
   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 version) December 1, 2002
 copy right by joard ast  

 admin_ rest. JSP} function: background management 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” />

<% / / verify the user’s identity and determine whether it is an administrator
if(!checkSessionBean.checkSessionBean(request,”sesUserRole”,”admin”)){
 out. Print (ShowDialog) “you don’t have permission to manage!”, “/index.html”));
 return;
}

//From the restaurant information file, {rest Get relevant data from XML #
Document doc;
NodeList restaurants;

String strAct;
int intId=0;
String strOperation=”show”;

//Incoming accept external parameters
strAct=(String)request.getParameter(“act”);

xmlBean.connXml(“webapps/canyin/data/restaurants.xml”);
doc=xmlBean.getXmlDoc();
restaurants =doc.getElementsByTagName(“restaurant”);

//It is determined according to the parameters passed in from the outside Operation of XML file
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 verification
  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;
    }
   }

  }

  

/ / get the number of existing records and set a 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;

/ / add 1 to the value of num # of restaurants attribute
  restNum.getAttributeNode(“num”).setNodeValue(String.valueOf(intNum));

/ / add a 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);

/ / call the bean and write 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 item of item (I) is the record to be modified
  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 verification
  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 (ShowDialog (“the record you want to modify doesn’t exist!”);
   return;
  }
  /*if(strAddress==null){
   out. Print (ShowDialog (“restaurant address cannot be empty!”);
   return;
  }*/

/ / indicates that the 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 (ShowDialog (“the record you want to modify doesn’t exist!”);
   return;
  }else{
/ / 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);

/ / call the bean and write the corresponding XML file
    writeXmlBean.writeXml(doc,”webapps/canyin/data/restaurants.xml”);

    response.sendRedirect(request.getRequestURI());  
    return; 

   }catch(Exception e){}
  }
 }
/ / delete
 if(strAct.equals(“del”)){
  int delId;
/ / record which item of item (I) is the record to be modified
  int intI=0;

  delId=Integer.parseInt(request.getParameter(“recordId”).trim());

  if(delId==0){
   out. Print (ShowDialog (“the record you want to modify doesn’t exist!”);
   return;
  }

The file: / / flag indicates that the 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 (ShowDialog (“the record you want to delete does not exist!”);
   return;
  }else{
/ / delete records
   try{
    Node delNode=(Node)restaurants.item(intI);

    doc.getElementsByTagName(“restaurants”).item(0).removeChild(delNode);

/ / call the bean and write 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 parameters
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 it is an empty record, the status of the change page is “new”
if (restaurants.getLength()==0){
 strOperation=”addnew”;
}
%>

<html>
<head>
< D title > catering system
<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=”22″>
    <tr> 
      <td width=”1″><img src=”../../images/top_r1.GIF” width=”62″ height=”22″></td>
< TD # width = 150 # align = “center” > catering system management – Restaurant Management</td>
      <td><img src=”../../images/top_r2.GIF” width=”294″ height=”22″></td>
< TD; width = 100; align = “center” > < a href = “/ index. HTML” > [exit the 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=”20″> </td>
< TD # class = tttable # height = 30 # width = “0” > restaurant name</td>
< TD # class = tttable # height = 30 # width = “0” > restaurant telephone</td>
      <td class=ttTable height=30 width=”0″> 
< div align = “center” > Restaurant Address < / div >
      </td>
      <td class=ttTable height=30 width=”30″> 
< div align = “center” > Modify < / div >
      </td>
      <td class=ttTable height=30 width=”30″> 
< 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 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=”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{ 
/ / display the normal format% >
    <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 (‘are you sure you want to delete this record? It will lead to the record being unusable? ”) {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 format% >
    <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 = “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 = “new” onclick = “javascript: window. Location. Href = ‘% = request. Getrequesturi()% >? Act = addnew’ ‘; > <%  
                } 
               } %>
               </td>
            <td>
< input “class = STBTM” type = “button” name = “button” value = “return” 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 in many places, because in the process of program development, too concise procedures often bring difficulties in later maintenance.

Development experience:

doc. getElementsByTagName(“restaurants”). The return value of item (int , I) is of node , type. If its attribute value is not to be called, it is not necessary to forcibly convert it to , element type. It can be operated directly. Due to the error of the developed reference materials, the system adopts forced transformation. You can consider using node # for direct operation in future development.

Trim () and {interger None of the parseint() functions can accept a value of type null

The left and right files under Tomcat , are directories, calculated from Tomcat , for details, see \ webapps \ canyin \ JSP \ userjudge JSP , about the writing method of XML , path.

If you are interested in the original code, please contact me through the following email, [email protected]

Recommended Today

JVM + GC parsing (premise knowledge concatenation)

Premise preparation JVM GC garbage collection JVM virtual machine monitoring, tuning and troubleshooting Tomcat and microservice optimization 1. Premise review 1.1. JVM memory structure 1.1.1、 JVM Architecture Overview The gray part in the figure isThread private, there is almost no garbage collectionOrange partThread sharing, the main place where garbage recycling occurs What is the class […]